How to find out map tile coordinates from latitude and longitude?

落花浮王杯 提交于 2019-12-22 04:43:24

问题


I'm using Mapbox vector tiles to gather specific data from a backend process. In the examples, they provide a link of a Manhattan tile:

http://a.tiles.mapbox.com/v3/examples.map-zr0njcqy/14/4823/6160.png

being the tile z/x/y coordinates 14/4823/6160

I know from navigating the map that the position of latitude 40.706119 and longitude -74.017554 is inside that tile.

I also deduct from how map works that working with zoom 14 the entire map is composed from 16384 x 16384 tiles being 14/0/0 the top left tile.

Yet taking the 180 degrees of latitude and 360 of longitude with the total tile cols and rows gives me 14/7464/4486 which is not the same tile. (Unless I didn't do it right?)

The question

How do I get the tile coordinates knowing the latitude and longitude?


回答1:


Digging in mapbox-studio source code I've found this little helper object:

https://github.com/mapbox/mapbox-studio/blob/5ac2ead1e523b24c8b8ad8655babb66389166e87/ext/sphericalmercator.js

that can be used like this:

> var a = new SphericalMercator()
> a.xyz([-74.017554, 40.706119], 14)
Object { minX: 4823, minY: NaN, maxX: NaN, maxY: 6160 }

14/4823/6160



来源:https://stackoverflow.com/questions/29218920/how-to-find-out-map-tile-coordinates-from-latitude-and-longitude

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!