triplebd69
asked on
Call MapQuest API
Need to call MapQuest Geocoding API and get the distance between 2 locations?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
what are all the Common URL Parameters you using in your c# code? is the outFormat xml or json?
can you give me your sample url without key value. also what error you are getting while parsing the response?
can you give me your sample url without key value. also what error you are getting while parsing the response?
Here is some php code that will do the job if that helps?
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$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;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
}
else if ($unit == "N") {
return ($miles * 0.8684);
}
else if ($unit == "Y") {
return ($miles * 1760);
}
else {
return $miles;
}
}
echo distance(50.850, -0.75838, 50.850, -0.85838, "M") . " Miles<br>";
echo intval(distance(50.840, -0.89838, 50.849, -0.89838, "Y")) . " Yards<br>";
echo distance(53.632293, -0.89838, 53.623393, -0.89838, "K") . " Kilometers<br>";
echo distance(50.84316, -0.89838, 50.84317, -0.89838, "N") . " Nautical Miles<br>";
?>
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$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;
$unit = strtoupper($unit);
if ($unit == "K") {
return ($miles * 1.609344);
}
else if ($unit == "N") {
return ($miles * 0.8684);
}
else if ($unit == "Y") {
return ($miles * 1760);
}
else {
return $miles;
}
}
echo distance(50.850, -0.75838, 50.850, -0.85838, "M") . " Miles<br>";
echo intval(distance(50.840, -0.89838, 50.849, -0.89838, "Y")) . " Yards<br>";
echo distance(53.632293, -0.89838, 53.623393, -0.89838, "K") . " Kilometers<br>";
echo distance(50.84316, -0.89838, 50.84317, -0.89838, "N") . " Nautical Miles<br>";
?>
ASKER