views:

31

answers:

1

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 = 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?

+1  A: 

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

See the documentation on Coordinate Transformations

Peter Bailey