Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.. enter image description here

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.

like image 423
Yaqub Ahmad Avatar asked May 07 '13 11:05

Yaqub Ahmad


People also ask

How do you call the marker click function from outside the map?

addListener(marker, 'click', (function(marker, i) { return function() { infowindow. setContent(locations[i][0]); infowindow. open(map, marker); } })(marker, i)); iconCounter++; } function AutoCenter() { // Create a new viewpoint bound var bounds = new google.

Which event is triggered when the map is continuously moved and dragged?

Then you will have a dragend event available.

How do I add an event to Google Maps?

To add an event, head to Google Maps on Android, tap on Contribute >Events > Add a public event. You can add an event name, tag the location, and add the time and date of the event as well. There's an option to add an image, write more event details, and add description as well.


1 Answers

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.

like image 139
MarsAndBack Avatar answered Oct 03 '22 01:10

MarsAndBack