Well, I see no other way to repeat all the lines in each request and filter them, calculating the distance between the selected zipcode and the others (all of them) based on Lat and Lon.
I use something similar ... http://webarto.com/googlemaps http://webarto.com/izrada-web-stranica/belgrade
PHP function for the distance between two LL ...
function distance($lat1, $lon1, $lat2, $lon2){ $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; return round($miles * 1.609344,3); }
I count it that way ...
$sql = mysql_query("SELECT * FROM geoip WHERE city = '$city'"); while($row = mysql_fetch_array($sql)){ $ll = explode(",",$row["ll"]); $x = distance(44.5428009033,18.6693992615,$ll[0],$ll[1]); $road = intval($x+($x/3)); echo "Distance between ".$row["city"]." and Tuzla is ".$x." kilometers of airline, that about ".$road." kilometers of road way."; }
source share