Question

I am trying to derive a latitude/longitude from the filename of maptiles generated from TileMill (zoom/x/y).

Using information from http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames I am using (PHP implementation)

$n = pow(2, $zoom);
$lon_deg = $x / $n * 360.0 - 180.0;
$lat_deg = rad2deg(atan(sinh(pi() * (1 - 2 * $y / $n))));
echo $lat_deg.','.$lon_deg;

to calculate from a maptile named z-x-y.png.

The value returned from the calculation does not related to the area covered by the tile.

An example being 7-36-70 (Jamaica) which returns a value of 16.875,61.6063963714 (location in the Arabian Sea).

Can anyone spot what is wrong?

Was it helpful?

Solution

$n should be 128, if that is 2**7. So, is that what your $n comes to?

Then $lon_deg should be 36/128*360 - 180 which would be -78.75 by my reckoning, if you assume the correct bracketing/precedence is (36/128)*360-180. And that looks pretty close to Jamaica...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top