LatLong calculated with PixelToLatLong varies from e.view.LatLong

I am using the following to calculate and display the cursor location:

latlong = map.PixelToLatLong(event.clientX, event.clientY);

Then, in the map.OnClick event, I use e.view.LatLong to display the cursor location. However, the two values are different!

Which one is right Since I'm adding data to a database based upon the location I feel it's important to get it right!



Answer this question

LatLong calculated with PixelToLatLong varies from e.view.LatLong

  • Thibaud

    Getting the accurate pixel location has been causing me problems. In a recent demo for drawing accurate polygons using the crosshair we had to actually correct the value by 1 pixel up and 3 pixels right for IE. (try it in local.live.com) We also had to use a more generic function to get the top and left position of the map div, listed below.
    John.

    var mapleft = 0;
    var maptop = 0;

    function SetMapOffsets(obj) {
    if (obj.offsetParent) {
    mapleft = obj.offsetLeft
    maptop = obj.offsetTop
    while (obj = obj.offsetParent) {
    mapleft += obj.offsetLeft
    maptop += obj.offsetTop
    }
    }
    }

    //usage
    function GetMap()
    {
    map = new VEMap('MapDiv');
    map.LoadMap(new VELatLong(-27, 152), 5 ,'r' ,false);
    SetMapOffsets(document.getElementById("MapDiv"));
    }


  • rwerner

    Thanks John!

    Just to wrap this up, I now use the following to get my LatLong (based upon John's code above):

    latlong = map.PixelToLatLong(event.clientX - mapleft, event.clientY - maptop)


  • LatLong calculated with PixelToLatLong varies from e.view.LatLong