Solved

# How to convert latitude and longitude to x,y coordinates - iphone?

Posted on 2011-05-12
1,898 Views
Hi,
I have a map in image format (.png file). I need to point Pins on the map based on the places latitude and longitude information.

If the coordinates are in X, Y instead of latitude and longitude, then I can point easily.

How do I convert the given lat and long to x, y coordinates? My map has different zoom level. For each zoom level, there is a separate map.

For example, I have the Bangalore map, I want to point Jayanagar on the map. I know the lat and long of Jayanagar. In addition to that, Bangalore map has 3 zoom levels. How can I convert the lat and long coordinates to x and y coordinates so that I can point Jayanagar on the map? The point should be visible in all the zoom levels.
0
Question by:Murugesh Perumal

LVL 27

Expert Comment

0

LVL 20

Expert Comment

You need to do some gauging anyway as it appears that the exact positioning of the map is not known.
Therefore I suggest you pick a distinguished feature (a street crossing etc.) near each corner of the picture, determine both its x,y-coordinates from the map picture and the lat,lan-coordinates by looking up the feature e.g. at www.openstreetmap.org (or google earth if no legal issues speak against that).
Then use simple linear interpolation for the complete picture. This should work as long as the map does not show too big a portion of the earth, or is located too close to one of the poles. With minor adjustions this would even work around the 180° meridian.
Regarding the zoom levels: You did not specify the magnification steps between levels, so you may want to repeat the process described above for all levels.

With most usual maps, the method can be reduced to measuring only two diagonally opposite vertices of the map.
0

Author Comment

I looked at the below url which may solve my problem
http://board.flashkit.com/board/archive/index.php/t-666832.html

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
latitude = Math.PI * latitude / 180;
longitude = Math.PI * longitude / 180;

latitude -= 1.570795765134; // subtract 90 degrees (in radians)

// and switch z and y
xPos = (app.radius) * Math.sin(latitude) * Math.cos(longitude);
zPos = (app.radius) * Math.sin(latitude) * Math.sin(longitude);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In the above formula, what app.radius means?

I searched on this but I could not get the value of it (app.radius in actionscript - adobe flash?)

Can you help me to find app.radius so that I can try out this solution?
0

LVL 27

Expert Comment

In the second link I sent you it shows that app.radius is the radius of the Earth.

x = radius_of_world * Math.cos(longitude) * Math.cos(latitude)
y = radius_of_world * Math.sin(longitude) * Math.cos(latitude)
0

LVL 27

Expert Comment

0

LVL 18

Expert Comment

it depends partly on the type of projection used to make the map in the first place.
0

Accepted Solution

Hi All,
Thanks for all of your support.

To convert the lat and long values to x, y on the map image, first find out the maps four side center points. After finding the center points latitude and longitude, use the below formula to calculate the X and Y position of each place with its lat and long values.

map_X_Constant = width of the map image / (westLeftCenterLongitude - EastRightCenterLongitude);
X = ((westLeftCenterLongitude - PlaceLongitude) * map_X_Constant);

map_Y_Constant = height of the map / (northTopCenterLatitude-southBottomCenterLatitude);
Y = ((52.695813-PlaceLatitude)*map_Y_Constant);

52.695813 - it is a variable factor. You need to try it out with different values to get the x,y point accuracy.
0

Author Closing Comment

The solution given is a tried out solution. works perfectly
0

## Featured Post

Complex Numbers are funny things.  Many people have a basic understanding of them, some a more advanced.  The confusion usually arises when that pesky i (or j for Electrical Engineers) appears and understanding the meaning of a square root of a nega…
This is a research brief on the potential colonization of humans on Mars.
Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…