[Webinar] Streamline your web hosting managementRegister Today

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 2679

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

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
Murugesh Perumal
1 Solution

Founder, Software Engineer, Data ScientistCommented:
0

Commented:
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 Commented:

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

Founder, Software Engineer, Data ScientistCommented:
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

Founder, Software Engineer, Data ScientistCommented:
0

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

Author Commented:
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 Commented:
The solution given is a tried out solution. works perfectly
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.