Translate

How to convert Android GPS coordinates into X,Y coordinates.

Without further math bullshit about all the conversion systems, when you have a bunch of Android GPS coordinates (which are compatible with Google Earth and Google Maps), and you want to draw them on a finite 2D plane, here’s what worked for me.

int x =  (int) ((PLANE_WIDTH/360.0) * (180 + lon));
int y =  (int) ((PLANE_HEIGHT/180.0) * (90 - lat));
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

2 Responses to “How to convert Android GPS coordinates into X,Y coordinates.”

  1. Joao Says:

    Im trying your algorithm but I cannot put this working yet, as the GPS coordinates are in double, when I cast the X and Y to int Im losing information and the integer value remain almost the same….Im putting the PLANE_WIDTH and PLANE_HEIGHT with the resolution of my screen device 320×480, like PLANE_WIDTH=320 and PLANE_HEIGHT=480 . Any tip are more than welcome?

    Here is my code:

    public void convertGPStoCartezian(double longitude, double latitude){
    int x = (int) ((320/360.0) * (180 + longitude));
    int y = (int) ((480/180.0) * (90 – latitude));
    }

    Cheers
    Joao

  2. gubatron Says:

    Yes, there will be loss of precision, this formula is not the best if you’re looking for too much accuracy, but it’s great to visualize a lot of data. It does not account for the curvature of the earth.

    If you want something more precise maybe you want to take a look at this
    http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowER_W12/howER_W12.html#DeductionEquirectangular

Leave a Reply