Saturday, September 7, 2013

central coordinates of regular map tiles

central coordinates of regular map tiles

I am trying to retrieve a set of static map tiles from Google Maps using
the simple web services API.
For zoom level 0, where there is only one tile, I simply specify the
center as (0,0), which is trivial. (And yes, I am aware, that the
south-north range is [-85.05113°,85.05113°] only, i. e. I have read about
mercartor projection (not only the wikipedia article).
So for zoom level 1 with 2×2 tiles I know that it'd be naive to think the
central coordinates of the tiles would be (±90,±45). I applied one of the
functions listed in above article's "Derivation of the Mercator
projection" section. In PHP this looks like
function mercor($aLat)
{
return rad2deg(asinh(tan(deg2rad($aLat))));
}
which always returns 50.498987 when passing in 45. I tried several of the
alternative expressions :-) all with the same result, indeed, and even
checked that value with a dedicated calculator.
Anyway, the value is obviously not correct, as you can see here (which was
supposed to show the north west quadrant of the Earth's map, but here the
equator is shifted to the north):
https://maps.googleapis.com/maps/api/staticmap?center=50.498987,-90&zoom=1&size=256x256&sensor=false
By trial and error I found the correct value to be close to 66.65, but I
have no idea how to calculate that. I tried several manipulations of the R
factor shown in the expressions in that mentioned "Derivation of the
Mercator projection" section, and also fiddled with the "Scale factor"
described in the same document, but whatever I do, I do not come close to
66.65.
Here you can see that 66.65 is the (close to) correct value, the equator
at the bottom edge:
https://maps.googleapis.com/maps/api/staticmap?center=66.65,-90&zoom=1&size=256x256&sensor=false
And taking an illustration like, for example,
http://upload.wikimedia.org/wikipedia/commons/f/fa/Mercator-proj.png,
and a tool like kruler, it also becomes obvious that it should be 66.65.
So, any idea would be greatly appreciated. Thanks in advance...
(Currently I'm trying it from withing HTML documents, because it's
relatively simple, but later I'd like to do it from an environment in
which I have no way to call JavaScript. so the JavaScript API is not an
option.)
(And if someone with 10+ Reputation would be so kind to turn the
googleapis and wikimedia "code" into links ;-) and then remove this
paragraph... thanks again.)

No comments:

Post a Comment