我需要谷歌地图中的可拖动标记

时间:2011-06-15 07:21:30

标签: google-maps

我需要谷歌地图中的可拖动标记..

所以我改了代码

var point = new GLatLng(app.entries [id] .data.lat,app.entries [id] .data.lng);

var m = new GMarker(point,app.icon [app.entries [id] .data.icon]);

var point = new GLatLng(app.entries [id] .data.lat,app.entries [id] .data.lng);

var m = new GMarker(point,{draggable:true});

我怎样才能找到标记的新位置..

1 个答案:

答案 0 :(得分:1)

我猜你正如文档中所解释的那样缺少听众。

请看一下这个样本:

var map = new GMap2(document.getElementById("map_canvas"));
var center = new GLatLng(37.4419, -122.1419);
map.setCenter(center, 13);

var marker = new GMarker(center, {draggable: true});

GEvent.addListener(marker, "dragstart", function() {
  map.closeInfoWindow();
  });

GEvent.addListener(marker, "dragend", function() {
  marker.openInfoWindowHtml("Just bouncing along...");
  });

// to get the point of dragger.
GEvent.addListener(markerD2, "drag", function(){
  document.getElementById("location").value=marker.getPoint().toUrlValue();
});


map.addOverlay(marker);

在这里工作得很好 - http://code.google.com/apis/maps/documentation/javascript/v2/overlays.html#Draggable_Markers