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?
First, open Google Maps on your computer, right-click the place you want to get coordinates. A pop-up window will show, you can find the latitude and longitude on the top. Left-click and copy them automatically.
Tile coordinates Tiles are called by zoom level. The x and y coordinates correspond to the tile's position on the grid for that zoom level. When determining which zoom level to use, remember each location is in a fixed position on its tile.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With