Latitude / Longitude and meters

2019-04-07 00:02发布

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!

2条回答
SAY GOODBYE
2楼-- · 2019-04-07 00:20

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.

查看更多
做自己的国王
3楼-- · 2019-04-07 00:25

I would like to add a very important comment (for the uninitiated or for those who have forgotten this):

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

conversion: radians = PI / 180 * degrees


(I apologize myself for making an answer , but with my current reputation of 35 i can't post a comment)

查看更多
登录 后发表回答