Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Longitude & Latitude to X Y on a map with Calibration points

If i have a jpeg map with size sizeX, sizeY

and some calibration points on the map (X, Y, Lon, Lat)

What would be the algorithm for calculating the corresponding XY point in the map with a given Longitude / Latitude pair?

like image 916
Jorge Avatar asked Sep 02 '09 18:09

Jorge


People also ask

How do you convert from longitude to meters?

Multiply the degrees of separation of longitude and latitude by 111,139 to get the corresponding linear distances in meters.


2 Answers

Here's what worked for me, without so much bs.

int x =  (int) ((MAP_WIDTH/360.0) * (180 + lon)); int y =  (int) ((MAP_HEIGHT/180.0) * (90 - lat)); 

The lat,lon coordinates were given to me by Android devices. So they should be in the same standard used by all Google Earth/Map products.

like image 152
Gubatron Avatar answered Nov 10 '22 23:11

Gubatron


If using the Equidistant Cylindrical Projection type map, here is what you need to do:

  1. Find the Latitude and longitude of your location tutorial here:
    http://lifehacker.com/267361/how-to-find-latitude-and-longitude
  2. Input that information into the following formulas:
    x = (total width of image in px) * (180 + latitude) / 360
    y = (total height of image in px) * (90 - longitude) / 180

    note: when using negative longitude of latitude make sure to add or subtract the negative number i.e. +(-92) or -(-35) which would actually be -92 and +35

  3. You now have your X and Y to plot on your image

    More information can be found about this formula and the map type here:
    http://www.progonos.com/furuti/MapProj/Dither/CartHow/HowER_W12/howER_W12.html#DeductionEquirectangular
like image 27
Anthony Master Avatar answered Nov 10 '22 23:11

Anthony Master