开发者

Adding pin to location clicked

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

           function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new 开发者_如何学JAVAGMap2(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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜