Convert pixel location to latitude/longitude & vise versa

前端 未结 1 1460
花落未央
花落未央 2021-02-04 17:48

I need to convert latitude longitude values into pixel positions as well as do the opposite. I\'ve found many solutions to go from lat/lng->pixel, but can\'t find anything on th

1条回答
  •  爱一瞬间的悲伤
    2021-02-04 18:19

    var y = Math.round(((-1 * lat) + 90) * (this.MAP_HEIGHT / 180));
    var x = Math.round((lng + 180) * (this.MAP_WIDTH / 360));
    

    Use some algebra and I came out with:

    var lat=(y/(this.MAP_HEIGHT/180)-90)/-1
    var lng = x/(this.MAP_WIDTH/360)-180
    

    Not completely confident in that math since it was done in my head, but those should work, just make sure to test them first.

    0 讨论(0)
提交回复
热议问题