Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Find nearest location" by Zip/Postal Code?

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?

like image 876
codemonkey613 Avatar asked Mar 24 '10 18:03

codemonkey613


People also ask

Can Google Maps search zip codes?

This ZIP Codes on Google Maps tool will show all ZIP Code boundaries, in the U.S. anyway. To see ZIP Codes for a specific city, address, etc, just type the city or address in the "Search places" box just above the map.

How do I find my ZIP code on Google Maps API?

ZIP code lookup The request format is: http://maps.googleapis.com/maps/api/geocode/json?address=ZIP_CODE&key=YOUR_API_KEY will, and in the response you get a lot of information, including for our purposes, that 92101 is the postal code for San Diego, California.


2 Answers

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

like image 193
Jon Black Avatar answered Sep 25 '22 17:09

Jon Black


You need a database of zip codes with longitude and latitude, from which you can calculate the distance.

like image 41
mikerobi Avatar answered Sep 26 '22 17:09

mikerobi