Home » Php » php – "Find nearest location" by Zip/Postal Code?

php – "Find nearest location" by Zip/Postal Code?

Posted by: admin July 12, 2020 Leave a comment


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?

How to&Answers:

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



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


Google Maps have restrictions in using is for business purposes, so you might want to consider those (restrictions) upfront.
From my former experience I would suggest MapQuest API. You can find details here:
http://developer.mapquest.com/ and some quick start guide here http://www.mapquest.com/features/developer_tools_oapi_quickstart

MapQuest seams to be better when it comes to commercial deals. Anyway, check their T&C before you will implement it in production.

They have JavaScriopt an I think regular WS for geo-location decoding.