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.

Foi útil?

Solução

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.

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top