Convert Longitude to Latitude

I need a function that maps gps positions to x / y values ​​as follows:

getXYpos(GeoPoint relativeNullPoint, GeoPoint p){ deltaLatitude=p.latitude-relativeNullPoint.latitude; deltaLongitude=p.longitude-relativeNullPoint.longitude; ... resultX=latitude (or west to east) distance in meters from p to relativeNullPoint resultY=longitude (or south to north) distance in meters from p to relativeNullPoint } 

I have seen some implementations of the "distance of two geopoints", but they all just calculate the distance along the air line. I think that deltaLongitude can be converted directly to meters, but the value of deltaLatitude depends on longitude. Does anyone know how this problem can be solved?

+7
mapping latitude-longitude coordinates
source share
3 answers

To begin with, you have latitude and longitude canceled. Longitude X and latitude measure Y.

Latitude is easily transformed into the distance between north and south. We know that 360 degrees is a complete circle around the Earth through the poles, and this distance is 40008000 meters . Until you need to take into account the errors associated with the fact that the earth is not absolutely spherical, the formula is deltaLatitude * 40008000 / 360 .

The tricky part is converting longitude to X, as you suspected. Since it depends on latitude, you need to decide what latitude you are going to use - you can choose the latitude of your origin, the latitude of your destination, or some arbitrary point between them. The circumference at the equator (latitude 0) is 40075160 meters. The circle circumference at a given latitude will be proportional to the cosine, so the formula will be deltaLongitude * 40075160 * cos(latitude) / 360 .

Edit: Your comment indicates that you had problems with the longitude formula; you could use degrees instead of radians in a cos call, which is a common rookie mistake. To make sure there is no ambiguity, the code in Python works here.

 def asRadians(degrees): return degrees * pi / 180 def getXYpos(relativeNullPoint, p): """ Calculates X and Y distances in meters. """ deltaLatitude = p.latitude - relativeNullPoint.latitude deltaLongitude = p.longitude - relativeNullPoint.longitude latitudeCircumference = 40075160 * cos(asRadians(relativeNullPoint.latitude)) resultX = deltaLongitude * latitudeCircumference / 360 resultY = deltaLatitude * 40008000 / 360 return resultX, resultY 

I chose to use relative absolute latitude to calculate X. This has the advantage that if you convert multiple points with the same longitude, they will have the same X; north-south lines will be vertical.

Edit again: I had to point out that this is a very simple formula, and you should know its limitations. Obviously, the earth is not flat, so any attempt to match it with the XY coordinates will require some compromises. The above formula I work best when the area you are converting is small enough to look flat, and where the slight curvature and non-parallelism of the north-south lines can be ignored. There is a whole science there to display projections; if you want to see some of the possibilities, Wikipedia would be a good place to start. This particular projection is known as the Equirectangular projection with some added scaling.

+13
source share

Harvesine function is what you need. Check it out for movable types . There are Distance, Bearing, Midpoint and other things. Javascript implementation works very well.

UPDATE

I found the Harvesine Java implementation of a function in another stack question

+2
source share

There are libraries on jstott.me.uk for PHP , Java and Javascript that do this, for example

 var lld1 = new LatLng(40.718119, -73.995667); // New York document.write("New York Lat/Long: " + lld1.toString() + "<br />"); var lld2 = new LatLng(51.499981, -0.125313); // London document.write("London Lat/Long: " + lld2.toString() + "<br />"); var d = lld1.distance(lld2); document.write("Surface Distance between New York and London: " + d + "km"); 
+1
source share

All Articles