[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2679
  • Last Modified:

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

  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.
Murugesh Perumal
Murugesh Perumal
1 Solution
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.
Murugesh PerumalAuthor Commented:
Thanks for your answer.

I looked at the below url which may solve my problem

// convert lat/long to radians
latitude = Math.PI * latitude / 180;
longitude = Math.PI * longitude / 180;

// adjust position by radians
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);
yPos = (app.radius) * Math.cos(latitude);

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?
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

CaptainCyrilFounder, 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)
z = radius_of_world * Math.sin(latitude)
CaptainCyrilFounder, Software Engineer, Data ScientistCommented:
it depends partly on the type of projection used to make the map in the first place.
Murugesh PerumalAuthor 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.
Murugesh PerumalAuthor Commented:
The solution given is a tried out solution. works perfectly

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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