开发者

Get latitude and longitude from Google Map

I want to get Latitude and Longitude during mouseover event of google map. I have written f开发者_如何学编程ollowing code,

  GEvent.addDomListener(document.getElementById("map"), "mousemove", function(e) {
    alert('mousemove:'+e.lat()+':'+e.lng());
  });

It gives me "undefined" output. What can be the solution for this?


You'll want to add a Listener, rather than a DomListener.

Also, the event will contain a single field called latLng which will have the getters lat and lng.

Try:

GEvent.addListener(document.getElementById("map"), "mousemove", function(e) {
    alert('mousemove:'+e.latLng.lat()+':'+e.latLng.lng());
});


I have got answer as follow

GEvent.addListener(map, 'click', function(overlay, point) {
     var latLngStr = "Lat = " + point.y + ", Long = " + point.x;
     map.openInfoWindow(point, latLngStr);
     document.getElementById("latbox").value=point.y;
     document.getElementById("lonbox").value=point.x;
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜