We have two coordinates (latitude, longitude) and let's assume we want to travel along a straight line between them. After traveling a certain distance along this line, we would like to calculate a new coordinate for this location. How can this be done?

Point startCoord = new Point(52.515343254180486, 13.384435940499088);
Point endCoord = new Point(52.51544771840784, 13.386055994744083);
double totalDistance = 110.23868303918874; // in meters
double intervalDistance = 50; // in meters

Note: Distances between points will always be fairly small.

Possible solution:

Based on this post we can find the angle between startCoord and endCoord.

Using the intervalDistance as hypotenuse, we can find x and y distances away from the startCoord using simple trig:

double dx = intervalDistance * Math.sin(angle);
double dy = intervalDistance * Math.cos(angle);

And based on this post, we can calculate the new coordinate based on the x and y distance away (in meters) from the startCoord.


This is actually both of the Geodetic Problems, used serially.

First you solve the Inverse (aka Reverse) problem, to obtain distance and bearing from two points, then you use the Forward (aka Direct) problem to travel distance and bearing from the first point.

I'd recommend you find a library that implements these functions, but it's certainly possible to port the US National Geodetic Survey FORTRAN code to Java yourself (I did, long ago, first to 'C' then to Java, but NGS has tweaked the code since then).

  • Thank you for defining the problem more formally
    – Hegemon
    Aug 29 '19 at 11:58

As per the answer from Vince, this is fairly easy with a library.

The Geodesic class from the geographiclib library provides a great implementation for Java (other language implementations are also available):

GeodesicData g1 = Geodesic.WGS84.Inverse(52.515343254180486, 13.384435940499088, 52.51544771840784, 13.386055994744083);
GeodesicData g2 = Geodesic.WGS84.Direct(g1.lat1, g1.lon1, g1.azi1, 50.0d);
System.out.println(g2.lat2 + ", " + g2.lon2); // 52.51539048629184, 13.385168382935976

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.