Lat, Long to pixel conversion

I don’t like this when there is a logical problem and you can’t solve it and you just think ” It should be really easy”
So my problem was, how to get latitude and longitude data converted into Pixel data. And by that I mean, hot to map this data to my map material in Flash.

And I solved it ;) So this it how it works.

What is the maximum Latitude and maximum Longitude? 90 and 180 ( and -90 and -180 ).
Then you need to know how big your map is So lets say map is 1500 by 1000
Then the conversion rate is

(1500 / ( 180*2) and
(1000 / ( 90*2)
Why times two? Because we have negative and positive Lat and Long values.

Then my map is positioned at 0,0 exactly, which in flash means that it is ends at 1500 and 1000. But 0.0 for the Lat and Long coordinates would be in the middle of the map. So I have to add half of the maps width or length to the value. So this is the calculation

Citylocation.x = Map.width / 2 + ( Longitude * ( Map.width / ( 180*2) ;
Citylocation.y = Map.height/ 2 + ( Latitude * ( Map.width / (90*2) ;

Print Friendly

Leave a Reply

8 + = eleven