0

I have a table where I store certain points of interest. Let's call them Skate parks for which I have the lat/long.

I would like to find all skate parks within a radius of X miles from a starting point with lat/long.

How would I do that?

orde
  • 5,233
  • 6
  • 31
  • 33
  • You have to iterate over all POIs and compute the distance betweeen its position and the starting point. Then it is clear for each if it is in or out, I'd say. You probably can make the same computation in a stored procedure inside your database. Should be faster, but more complex if you never did that before. – arkascha Mar 26 '15 at 15:24
  • See this post on SO http://stackoverflow.com/questions/21168380/use-mysql-spatial-extensions-to-select-points-inside-circle many details much useful – Dave Mar 26 '15 at 16:29

1 Answers1

0

Haversine formula. You get the distance of every park and return those that are within X.

SELECT id, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) ) + sin( radians(37) ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;

37 and -122 are the lat and lng of your "starting point" and 25 is X

This may help https://developers.google.com/maps/articles/phpsqlsearch_v3