Latitude / Longitude and meters

12,116

Solution 1

The haversine formula can be simplified a great deal when you work in north-south and east-west directions only.

If Earth's circumference is C, the point at d kilometers to south of a given point is 360*d/C degrees to the south. The point at d kilometers to east is 360*d/(C*cos(latitude)) degrees to the east. The cosine in the denominator comes from the fact that the length of the longitude at a given latitude shorter than the equator by that much.

So if the Earth's circumference is 40075.04 km, to move 5 m to the north/south you would add/subtract 0.0000449 from the latitude and use the same longitude. To move 5 m to the west/east you would use the same latitude and add/subtract 0.0000449/cos(latitude) to the longitude. Don't forget about the edge cases though: near poles you have to clamp latitude to 90°, and near longitude 180° you'll have too add or subtract 360° to keep the longitude in the correct range.

With your numbers the range turns out to be approximately:

latitude:  [23.23903 ; 23.23911]
longitude: [50.45781 ; 50.45791]

Update: Note that this still assumes that the Earth is a perfect sphere, which it's not. The GPS system for example models the Earth as an ellipsoid where the equator is at 6378.137km and the poles are at 6356.7523142km from the center of the Earth. The difference is about 1/300th and matters a great deal for many applications, but in this case it's within the margin of error.

Correcting the formula for the longitude should be simple since the parallels are still circles: you would just have to swap cos(latitude) for the correct coefficient. Calculating the correct latitude is harder because the meridians are not circles but ellipses, and the arc length of an ellipse cannot be calculated using elementary functions, so you must use approximations.

Solution 2

I would like to add a very important comment:

The cosine is to be calculated on the latitude in radians and not in degrees.

conversion: radians = PI / 180 * degrees

Share:
12,116
Apaachee
Author by

Apaachee

Updated on June 19, 2022

Comments

  • Apaachee
    Apaachee almost 2 years

    I have a small algorithmic problem.

    I am developing an Android application. I get GPS coordinates. For example: latitude: 23.23907, longitude: 50.45786.

    So I get a point. I want to compute bounds details on this point plus or minus 5 meters. I.e.:

    [23.23907 - 5 meters ; 23.23907 + 5 meters]
    [50.45786 - 5 meters ; 50.45786 + 5 meters]
    

    How to make this calculation?

    Thank you very much!

  • Apaachee
    Apaachee about 11 years
    Thanks a lot, this is simple !
  • Admin
    Admin over 3 years
    Yes ok but that's not the reason the error would still remain significant. The error is mostly due to what has been updated above: "...this still assumes that the Earth is a perfect sphere, which it's not."