开发者

Get Latitude and Longitude under cursor in GoogleMaps without map.onMouseMove

I have GoogleMaps-object. Also I have SouthWest and NorthEast point in GLatLng-format. Also I have (x,y) of cursor over my object. I want know GLatLng under cursor without use map.onMouseMove (only use DOM-onMouveMove). I try write JavaScript-code:

        var w = map.getSize().width;
        var h = map.getSize().height;
        var left = map.getBounds().getSouthWest().lat();
        var right = map.getBounds().getNorthEast().lat();
        var top = map.getBounds().getSouthWest().lng();
        var bottom = map.getBounds().getNorthEast().lng();
        var x = e.pageX - map_canvas.offsetLeft;
        var y = 开发者_JS百科e.pageY - map_canvas.offsetTop;
        var lng = top + (bottom - top) * x * 1.0 / w;
        var lat = left + (right - left) * (h - y) * 1.0 / h;

But in this way I do not have enough accuracy. What is the normal transformation formulas in the geographic coordinates of the screen?


I think you can use GMap2.fromContainerPixelToLatLng() or GMap2.fromDivPixelToLatLng()

See the documentation on Coordinate Transformations

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜