Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mapbox

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?

like image 492
dnuske Avatar asked Mar 23 '15 19:03

dnuske


People also ask

How do I extract coordinates from a map?

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.

What is tile coordinate?

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.


1 Answers

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

like image 160
dnuske Avatar answered Nov 22 '22 10:11

dnuske