Calculating new longitude, latitude from old + n meters

I want to create 2 new longitude and 2 new latitudes based on a coordinate and a distance in meters, I want to create a nice bounding box around a certain point. It is for a part of a city and max ±1500 meters. I therefore don't think the curvature of earth has to be taken into account.

So I have 50.0452345 (x) and 4.3242234 (y) and I want to know x + 500 meters, x - 500 meters, y - 500 meters, y + 500 meters

I found many algorithms but almost all seem to deal with the distance between points.


Solution 1:

The number of kilometers per degree of longitude is approximately

(pi/180) * r_earth * cos(theta*pi/180)

where theta is the latitude in degrees and r_earth is approximately 6378 km.

The number of kilometers per degree of latitude is approximately the same at all locations, approx

(pi/180) * r_earth = 111 km / degree 

So you can do:

new_latitude  = latitude  + (dy / r_earth) * (180 / pi);
new_longitude = longitude + (dx / r_earth) * (180 / pi) / cos(latitude * pi/180);

As long as dx and dy are small compared to the radius of the earth and you don't get too close to the poles.

Solution 2:

The accepted answer is perfectly right and works. I made some tweaks and turned into this:

double meters = 50;

// number of km per degree = ~111km (111.32 in google maps, but range varies
   between 110.567km at the equator and 111.699km at the poles)
// 1km in degree = 1 / 111.32km = 0.0089
// 1m in degree = 0.0089 / 1000 = 0.0000089
double coef = meters * 0.0000089;

double new_lat = my_lat + coef;

// pi / 180 = 0.018
double new_long = my_long + coef / Math.cos(my_lat * 0.018);

Hope this helps too.

Solution 3:

For latitude do:

var earth = 6378.137,  //radius of the earth in kilometer
    pi = Math.PI,
    m = (1 / ((2 * pi / 360) * earth)) / 1000;  //1 meter in degree

var new_latitude = latitude + (your_meters * m);

For longitude do:

var earth = 6378.137,  //radius of the earth in kilometer
    pi = Math.PI,
    cos = Math.cos,
    m = (1 / ((2 * pi / 360) * earth)) / 1000;  //1 meter in degree

var new_longitude = longitude + (your_meters * m) / cos(latitude * (pi / 180));

The variable your_meters can contain a positive or a negative value.

Solution 4:

Have you checked out: How do I find the lat/long that is x km north of a given lat/long ?

These calculations are annoying at best, I've done many of them. The haversine formula will be your friend.

Some reference: http://www.movable-type.co.uk/scripts/latlong.html

Solution 5:

I had to spend about two hours to work out the solution by @nibot , I simply needed a method to create a boundary box given its center point and width/height (or radius) in kilometers:

I don't fully understand the solution mathematically/ geographically. I tweaked the solution (by try and error) to get the four coordinates:

North:

private static Position FromKmToNPosition(Position p, double km)
{
    double r_earth = 6378;
    var pi = Math.PI;
    var new_latitude = p.Lat + (km / r_earth) * (180 / pi);
    return new Position(new_latitude, p.Long);
}

East:

private static Position FromKmToEPosition(Position p, double km)
{
    double r_earth = 6378;
    var pi = Math.PI;
    var new_longitude = p.Long + (km / r_earth) * (180 / pi) / Math.Cos(p.Lat * pi / 180);
    return new Position(p.Lat, new_longitude);
}

South:

private static Position FromKmToSPosition(Position p, double km)
{
    double r_earth = 6378;
    var pi = Math.PI;
    var new_latitude = p.Lat - (km / r_earth) * (180 / pi);
    return new Position(new_latitude, p.Long);
}

West:

private static Position FromKmToWPosition(Position p, double km)
{
    double r_earth = 6378;
    var pi = Math.PI;
    var new_longitude = p.Long - (km / r_earth) * (180 / pi) / Math.Cos(p.Lat * pi / 180);
    return new Position(p.Lat, new_longitude);
}