Find the nearest latitude and longitude

The question of latitude and longitude ... Probably stupid.

I have a set of latitudes and longitudes for different places. And I have the latitude and longitude of the location that I am in.

Now I have to find the nearest places from my places from the many latitudes and longitudes that I have. Do you have any special way of calculating it or is it just subtracting and checking the difference?

Could you talk about this?

Thanks J

+8
source share
2 answers

It depends on how the points are located.

For example, if most points are parked, then Euclidean Distance should work well.

In other cases, you need to calculate the Geodesic Distance . This link should help you with more information.

Here is the conversion from decimal to Degree-Minute-Second and vice versa.

amuses

+9
source

You can use this SQL. he will select the closest Lat, Lng from your records in the database.

SELECT id, lat, lng, ((ACOS (SIN (your_lat * PI () / 180) * SIN (lat * PI () / 180) + COS (your_lat * PI () / 180) * COS (lat * PI ( ) / 180) * COS ((your_long - lng) * PI () / 180)) * 180 / PI ()) * 60 * 1.1515) AS distance FROM your_table_name HAS distance <= '10' ORDER BY distance ASC LIMIT 0, ten

Hope this helps.

+4
source

Source: https://habr.com/ru/post/1241000/


All Articles