first of all use a map and ask the user to set his approximate location, get that values,
with this code get the distance to each store:
google.maps.geometry.spherical.computeDistanceBetween (latLngA, latLngB);
from https://developers.google.com/maps/documentation/javascript/reference?hl=en-US#spherical
now choose the shorter and output it
but I'd rather ask him to input the City and get the distance through Wolfram api request
$city=customer_city;
$north=store_north; //coordinate_l
$west=store_west; //coordinate_L
$wolfram_query="http://api.wolframalpha.com/v2/query?appid=".$appid."&input=distance%20from%20".$city."%20to%20".$north."N%20".$west."W%20in%20km&format=image,plaintext";
and get the distance from the xml answer leaving google maps out
an other option using zipcodes is to calculate the spherical distance from two coordinates with this php function inside a while loop going through all the lat and long of the sores:
function calcDist($lat_A, $long_A, $lat_store[i], $long_store[i]) {
$distance = sin(deg2rad($lat_A))
* sin(deg2rad($lat_B))
+ cos(deg2rad($lat_A))
* cos(deg2rad($lat_B))
* cos(deg2rad($long_A - $long_B));
$distance = (rad2deg(acos($distance))) * 69.09;
return $distance;
}
distance is in miles, if you want the distance in km use this
function miles2kms($miles) {
$ratio = 1.609344;
$kms = $miles * $ratio;
return $kms;
}
and you can retrieve the lat and long of the zip code using this database:
http://sourceforge.net/projects/zips/files/#files
or this
http://postcodedb.sourceforge.net/dumpCSV.php
to improve the result of the distance you should use Haversine or Vincenty calculations... which are a little more complex..
... but what we like of the net is that someone has surely done this before we did, and of course shared his efforts!
http://www.phpclasses.org/package/6480-PHP-Calculate-the-distance-between-Earth-two-points.html
this is a class that implements haversine distance! this might be better... if you want to use Vincenty try this: Implementing Vincenty's Formula in PHP , try which one gives you the best results, even if the most accurate will always be wolfram, mathematicians worked on that, so that works pretty well ;)