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

Posted on 2011-05-12
Last Modified: 2012-05-11
  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.
Question by:Murugesh Perumal
    LVL 27

    Expert Comment

    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 (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.

    Author Comment

    by:Murugesh Perumal
    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?
    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)
    z = radius_of_world * Math.sin(latitude)
    LVL 27

    Expert Comment

    LVL 18

    Expert Comment

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

    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.

    Author Closing Comment

    by:Murugesh Perumal
    The solution given is a tried out solution. works perfectly

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    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…
    Article by: Nicole
    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 ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now