0
votes

Found a plenty of answers to question how to calculate distance by lat/lon and nothing for a "reverse" problem.

I have a displacment in X and Y and a GPS point (lat/lon), yet need to calc coordinates for a new point.

Using formula:

double deltaLat = dy / EARTH_RADIUS; 
double deltaLon = dx / EARTH_RADIUS;
double lat = locLat + Math.signum(dy) * Math.toDegrees(deltaLat); // formula correct
double lon = locLon + Math.signum(dx) * Math.toDegrees(deltaLon);

It's accurate for calculating latitude, but for longitude I get about 10–15% error. Does anyone have the same issue? Any possible formulas to calculate longitude by displacement?

2
displacement you have but in which directionvipin

2 Answers

1
votes

The reason you're getting 10-15% error in longitude is because for longitude you cannot use the earth's radius to compute your displacement. Instead, you need to use the radius of the "circle" at the corresponding latitude. Therefore using your formula your longitude calculations should be more like

double deltaLon = dx / (EARTH_RADIUS * cos(locLat))

However this may give you undesired results around the poles, as cos(locLat) will get close to 0, so you may want to have some special cases for the poles (or even around them). Logically, if you think about, if you're at the pole, moving any distance along the x axis will not get your anywhere anyway.

0
votes

Simplest but not the best solution is:

double deltaLat = dy / EARTH_RADIUS; // up-down
double deltaLon = dx / EARTH_RADIUS ; // left-right
double lat = locLat + Math.signum(dy) * Math.toDegrees(deltaLat); // formula correct
double lon = locLon + Math.signum(dx) * Math.toDegrees(deltaLon * 1.195);