Php – “Find nearest location” by Zip/Postal Code

google mapsMySQLPHP

I need a "find nearest location" on our website.

Where visitor enters their zip/postal code, then they are redirected to specific webpage for our nearest location. We have forty USA and Canada locations.

How can I build something like this? Could I do this with the Google Maps API? I already have a custom map on Google Maps. It's plotted with our locations. It would be nice to send Google Maps a command to say "what's our nearest location at ________ zip code".

Any suggestions?

Best Answer

if you have the longitudes and latitudes of each zipcode (search google) you can use the Haversine Formula to calculate nearest neighbours.

http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe

Related Topic