Creating a Store Locator On Your Website

At the beginning, you need have a list of store locations with Latitude/Longitude points. If your list doesn’t only contain Latitude/Longitude points, then you can use Google Maps API to get them.

Here is a php code sample:

 

The next thing is to calculate the distance from a given location to the store locations, and find the nearest locations. The distance calculation is based on the Haversine formula. You can use any program language to use that formula.

The recommend solution is using Google Maps API v3. Here is a tutorial from Google Geo APIs Team : Creating a Store Locator with PHP, MySQL & Google Maps

If you want to use Javascript rather than PHP, then here is a JS functions you can use:  Calculate distance, bearing and more between Latitude/Longitude points

For more about Google Maps API, check here: The Google Geocoding API

Other Map API, have not been tested yet: Map Quest    http://developer.mapquest.com/

For other requirement, like get a quickest route between two points,  here is a php solution by using Google Maps API: How to Build a Distance Finder with Google Maps API 

 

Leave a Reply