1

I have a table of addresses 'street', 'city', 'state' and 'zip'.

I can pull the grid for the full address with google maps API, and the haversine formula is adequate, but how do I search based on that?

Example. Say someone searches for "New York City" how can I search for addresses closest to that lat/long? I know I need to convert that to lat/long.

Should I add another field so I can store the addresses in lat/long? If so, what do I do to search based on distance?

mbreezy
  • 85
  • 6
  • 3
    If you have an `origin` lat/long, you can use math to determine a radius of other lat/long coordinates within range. Then just query the db for records with lat/long inside of the min/max values. – helion3 Feb 02 '14 at 05:48
  • It would depend. Do you want driving distance or just linear distance? Linear distance, do what @BotskoNet said, otherwise, you will probably have to use the google maps api and figure it out in a PHP script, store each ID and Distance in an array, and then get the closest X number of places to the start point. – Jacques ジャック Feb 02 '14 at 05:52

1 Answers1

1

I actually found what I was looking for on here. It took me a while because I wasn't searching for the right terms, but figured it out. MySQL Great Circle Distance (Haversine formula)

That was what I was going for. I hope this helps someone else!

Community
  • 1
  • 1
mbreezy
  • 85
  • 6