I am trying to return the total distance of a route, rather than the great circle distance. I have a complicated method, but I'm not convinced with the result:
function getFPDistance(){
$schedule = SchedulesData::getScheduleDetailed($_GET['plan']);
$params->deplat = $schedule->deplat;
$params->deplng = $schedule->deplng;
$params->arrlat = $schedule->arrlat;
$params->arrlng = $schedule->arrlng;
$params->route = $_POST['route'];
$routedata = NavData::parseRoute($params);
$depairport = OperationsData::getAirportInfo($schedule->depicao);
$arrairport = OperationsData::getAirportInfo($schedule->arricao);
$end = (count($routedata) - 1);
$total = 0;
$a = -1;
$b = 0;
# Put lat/lng of each waypoint into array
$lat = array();
$lng = array();
foreach($routedata as $wp){
$lat[] = $wp->lat;
$lng[] = $wp->lng;
}
# Calculate the distance between each waypoint in the array
for($i=0; $i<$end; $i++){
$a++;
$b++;
$dist1 = distance($lat[$a], $lng[$a], $arrairport->lat, $arrairport->lng);
$dist2 = distance($lat[$b], $lng[$b], $arrairport->lat, $arrairport->lng);
$dist = $dist1 - $dist2;
$total = $total + $dist;
}
# Get the distance between the departure airport and the first waypoint
$dep_to_first = distance($depairport->lat, $depairport->lng, $lat[0], $lng[0]);
# Get the distance between the last waypoint and arrival airport
$last_to_arr = distance($lat[$end], $lng[$end], $arrairport->lat, $arrairport->lng);
# Add these to the total
$total = $total + $dep_to_first + $last_to_arr;
return round($total);
}
For EGCC-GCTS, this returns 1650nm, with GC distance being 1648nm, route shown below.
NOKIN UN862 LAMAT UN90 NOTRO UM30 SALCO UN864 MONTO UN857 TERTO
Any ideas?