# Algorithm to Calculate Lat/Long based on distance from central Lat/Long

#### RicherSims

Resource contributor
This may be extremely simple, but the math seems to be escaping me and my research hasn't given me a definite answer.

I have an object with several vertices whose position from the origin is known in meters. (X and Y). We will assume the object is flat.
I also know the object origin is at a given location. (example 13N, 51W).
How can one calculate the lat/long coordinate of every vertex given their X and Y distance from the origin?

#### RicherSims

Resource contributor

It wasn't as straight forward as imagined.

Code modified from here:

Code:
``````//ASSUMES UNITS IN METERS
function get_new_coordinates(central_coord:TCoordinate; X,Y: real):Tcoordinate;
const R:real = 6378137;  //Earth Radious in M
var central_lat,central_long,new_lat,new_long,bearing, distance: real;
begin
central_lat := central_coord.lat * (pi/180);
central_long := central_coord.long * (pi/180);

bearing := ArcTan2(Y,X);
distance := sqrt(sqr(X)+sqr(Y));

new_lat := arcsin(sin(central_lat)*cos(distance/R) + cos(central_lat)*sin(distance/R)*cos(bearing));
new_long := central_long + arctan2(sin(bearing)*sin(distance/R)*cos(central_lat),cos(distance/R)-sin(central_lat)*sin(new_lat));

//back to degrees
new_lat := new_lat * (180/pi);
new_long := new_long * (180/pi);

//round to 8 decimal places
result.lat := roundto(new_lat,-8);
result.long := roundto(new_long,-8);

end;``````

• rhumbaflappy

#### WarpD

• RicherSims

#### DragonflightDesign

Resource contributor
To add to Ed's answer; Ed Williams presents the formulae and worked examples so clearly that it is really easy to convert to C-code and then to plug in his examples to make sure your code is correct. BTDT and written a shedload of black boxes so I don't have to do it again.