How can i capture the click event when a default marker/place is clicked on googlemaps?

后端 未结 4 1295
清酒与你
清酒与你 2020-12-20 17:08

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..

相关标签:
4条回答
  • 2020-12-20 17:35

    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.

    0 讨论(0)
  • 2020-12-20 17:46

    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.

    0 讨论(0)
  • 2020-12-20 17:54

    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?

    0 讨论(0)
  • 2020-12-20 17:54

    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

    0 讨论(0)
提交回复
热议问题