You need spherical trigonometry to calculate distances correctly on the surface of the globe. The best way is using haversines - see http://www.movable-type.co.uk/scripts/latlong.html.
Calculate nearest GPS points near directions MySQL
-
11-03-2022 - |
Pergunta
i have set of GPS points in database. I recently tried to select only those near to my location. I could do that with MySQL select. I use google maps to display them.
But now, i need to calculate nearest points in radius let's say 20km around directions - line segment between two gps points.
I have drawn it on a picture. I have two points A, B and i need to display only those points near to path between them.
- Yellow line is the line between A and B
- I want to select only markers in red area
http://i.stack.imgur.com/9ZbUd.jpg
Thank you for your solutions.
Solução
Outras dicas
You can calculate distances using one of functions in the following page:
Shortest distance between a point and a line segment
(if there is no mysql function you can translate some in mysql)
Then just limit your search with points that have this distance no more then you need.