问题
I am working with Google Maps API V3. The googlemaps displays markers for some places/location by default, I need to capture the click event when one of them is clicked..

I have tried to use the click event of the map but it not works because the user is clicking the marker not the map, code is given:
google.maps.event.addListener(mymap, 'click', function () {
alert('clicked');
});
Can someone give me an idea how to do it?
EDIT: I can find no suitable Event in the available Events, which can help me!
Please note that I am not talking about the custom Markers (Created by User), these are default markers, googlemaps displays them by default.
回答1:
Here's a clean solution straight from Google: https://developers.google.com/maps/documentation/javascript/examples/event-poi
You can easily customize the default infowindow for POI's. Just ignore the route-making feature of the tutorial.
回答2:
I have never tried it but could you retrieve the list of places that Google has displayed using the Google Places API and then establish your own pins and click events for them?
回答3:
It's a bit hacky, and doesn't work on IE < 9, but you can listen on dom event, to detect the creation of the window, using
Mutation Observer
Here is a plunkr to demonstrate : http://plnkr.co/edit/pGep9OZFligLhRtHlhgk You can check in the console, an event is fired (actually twice) when you click on a POI.
回答4:
Note that the OP is asking about doing this using the GMAP3 library, which is a jQuery plugin library that adds an API layer on top of the Google Maps layer. it is absolutely correct to say that the Google API is to use google.maps.addListener, but I think that the OP wants something that's closer to the GMAP3 example using addMarkers, but listening to the click event. With that in mind, I modified the example from GMAP3 and changed the mouseenter event to the click event and got rid of the mouseleave event.
Refer
来源:https://stackoverflow.com/questions/16417600/how-can-i-capture-the-click-event-when-a-default-marker-place-is-clicked-on-goog