문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top