[OSM-dev] Calculate Latitude coordinate in map

al_ku at web.de al_ku at web.de
Sun Jan 6 15:39:30 GMT 2008


Hello guys,

 

I just started to work a little with your map and wanted to write a small
test application to see it in action (I wanted to used it later for easier
map editing on OSM).

 

Now I have a little problem. Your map is a rectangular with the same width
as height. So for the Longitude (width) it's pretty easy for me to convert
the pixel-coordinates to actual geographical coordinates:

 

(x/width)*360.0f-180.0f

 

This gives me the coordinate of x (my mouse pointer on the map).

 

I tried to do the same for the Latitude (height):

 

((y/height)*180.0f-90.0f)*-1.0f

 

Well, it doesn't seem to give me the correct results. This is probably
because the earth is an ellipse and you display it as a rect. So the
distance between each degree Latitude decrease in your rectangular map, but
I absolutely have no idea of how to correctly calculate it.

I've spent some time searching and the best I've come up so far are these
formulars:

 

http://en.wikipedia.org/wiki/Latitude#Common_.22latitude.22

 

But there are so many of them and I don't know which to use (if any of these
is even the right one). I tested some but nothing good came out of it L

 

 

Please guys, can someone put me in the right direction?

 

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20080106/2592a1d3/attachment.html>


More information about the dev mailing list