Latitude / Longitude and meters

I have a little algorithmic problem.

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

So, I get it. I want to calculate the border data at 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!

+6
source share
2 answers

The haversine formula can be greatly simplified if you work only in the north-south and east-west directions.

If the Earth’s circumference is C, a point at a distance of d kilometers south of this point is 360 * d / C degrees south. Point in d kilometers east 360 * d / (C * cos (latitude)) degrees east. The cosine in the denominator assumes that the longitude at this latitude is shorter than the equator.

So, if the Earth’s circumference is 40,075.04 km, to move 5 m to the north / south you add / subtract 0.0000449 from latitude and use the same longitude. To move 5 m west / east, you must use the same latitude and add / subtract 0.0000449 / cos (latitude) by longitude. Do not forget about edge cases: near the poles you need to pinch the latitude to 90 °, and near the longitude of 180 ° you will also add or subtract 360 ° to keep the longitude in the correct range.

With your numbers, the range is something like this:

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

Update: Please note that this still suggests that the Earth is an ideal sphere that it is not . For example, the GPS system models the Earth as an ellipsoid, where the equator is at an altitude of 6378.137 km, and the poles - at 6356.7523142 km from the center of the Earth. The difference is about 1/300 and is of great importance for many applications, but in this case it is within the margin of error.

Correcting the longitude formula should be simple, as the parallels are still circles: you just need to swap cos(latitude) with the correct coefficient. Calculating the correct latitude is more difficult, since the meridians are not circles, but ellipses, and the length of the ellipse arc cannot be calculated using elementary functions, so you should use approximations.

+14
source

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

the cosine is calculated at latitude in radians, not degrees.

conversion: radian = PI / 180 * degrees


(I apologize for the answer, but with my current reputation of 35 I cannot leave a comment)

+4
source

All Articles