views:

24

answers:

2

I have an embedded Google map with my web application in ASP.NET 3.5.

I have implemented reverse geocoding (getting address from latitude and longitude) on Map click.

Now, I need the same but on marker click.

How should I code marker click?

+1  A: 

For each of your markers, add the following event handler for the click event. This assumes you're using the version 2 API.

// pass in a reference to your marker object and 
// bind the function to the click event
GEvent.addListener(marker, "click", function() {        
    // perform your geocoding here
});

You can grab the coordinates of the marker with its getLatLng() method, which returns a GLatLng object.

More info can be found here.

Tim S. Van Haren
+1  A: 

You can add a call to your reverse-geocode function within the event listener for the marker's OnClick event.

google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); }); Is a normal thing you might do to have the infowindow open when you click a marker. Add another function() to it.

Evan
This is for V 3 of the API
Evan