Something like the following:
Code: Select all
$result = mysql_query("SELECT `foo`,`bar`,`lat`/`long` AS `distance` FROM `table` ORDER BY `distance` ASC");Moderator: General Moderators
Code: Select all
$result = mysql_query("SELECT `foo`,`bar`,`lat`/`long` AS `distance` FROM `table` ORDER BY `distance` ASC");Code: Select all
// radius is miles
$query = "WHERE (POW((69.1*(Longitude-\"$Longitude\")*cos($Latitude/57.3)),\"2\")+POW((69.1*(Latitude-\"$Latitude\")),\"2\"))<($radius*$radius)";Code: Select all
function calculate_mileage($lat1,$lat2,$lon1,$lon2,$unit){
$lat1 = deg2rad($lat1);
$lon1 = deg2rad($lon1);
$lat2 = deg2rad($lat2);
$lon2 = deg2rad($lon2);
// Find the deltas
$delta_lat = $lat2 - $lat1;
$delta_lon = $lon2 - $lon1;
// Find the Great Circle distance
$temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2);
$distance = 3956 * 2 * atan2(sqrt($temp),sqrt(1-$temp));
if($unit == "M"){
return round($distance,2);
}
if($unit == "K"){
return round($distance*1.609,2);
}
return false;
}Code: Select all
$query = "ORDER BY POW((69.1*(Longitude-\"$Longitude\")*cos($Latitude/57.3)),\"2\")+POW((69.1*(Latitude-\"$Latitude\")),\"2\") ";