views:

19

answers:

1

Hey guys,

I've got the following Google map on my website..

           function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(53.347247,-6.259031), 13);
    map.setUIToDefault();

    GEvent.addListener(map, "click", function(overlay, latLng)
{
    // display the lat/lng in your form's lat/lng fields
    document.getElementById("lat").value = latLng.lat();
    document.getElementById("lng").value = latLng.lng();
});
  }
 }

What would I need to add / edit so that whenever a user clicked a location on the map a pin / balloon / any kind of indicator would be dropped at the location they clicked?

Thanks.

+1  A: 

All you have to do is add this to your existing addListener call:

if (latLng) {
    marker = new GMarker(latLng, {draggable:true});
    map.addOverlay(marker);
}

See this article linked by Google in their API information for an even more advanced example that lets your users edit the map data.

Update: Changed case of 'l' to 'L' in latLng.

Tony Miller
Doesn't appear to of worked.
Ulkmun