Convert lat/long to pixel X&Y co-ordinates

后端 未结 3 1843
野趣味
野趣味 2021-01-01 06:44

This type of question seems to have been asked numerous times but none of the solutions posted get me anywhere near the answer I need.

I have this map of Northland,

3条回答
  •  自闭症患者
    2021-01-01 07:11

    in Javascript....

    var lat=-35.3989854471;
    var long=173.504676819;
    
    var imageNorthLat=???;
    var imageSouthLat=???;
    
    var imageWestLong=???;
    var imageEastLong=???;
    
    var imageLongPixels=400;
    var imageLatPixels=400;
    
    var pixelsPerLat=imageLatPixels/(imageNorthLat-imageSouthLat);
    var pixelsPerLong=imageLongPixels/(imageEastLong-imageWestLong);
    
    var xPixelPosition=(long-imageWestLong)*pixelsPerLong;
    var yPixelPosition=Math.abs(lat-imageNorthLat)*pixelsPerLat;
    

    I didn't try to run this, so there's probably a bit of debugging necessary, and the x and y pixel positions would have to have added to them the x and y positions of the top left or your map. But you can see the idea. And, of course, I may not have understood what you're really asking.

提交回复
热议问题