mbreezy
mbreezy

Reputation: 85

How can I search mysql based on distance

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?

Upvotes: 1

Views: 226

Answers (1)

mbreezy
mbreezy

Reputation: 85

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!

Upvotes: 1

Related Questions