Esempio n. 1
0
 function bearing($tx, $rx)
 {
     $my = qra2latlong($tx);
     $stn = qra2latlong($rx);
     $bearing = bearing($my[0], $my[1], $stn[0], $stn[1]);
     return $bearing;
 }
Esempio n. 2
0
 function calcBearing($points)
 {
     $bearing = 0;
     for ($i = 0; $i < sizeof($points) - 1; $i++) {
         $bearing += bearing($points[$i][1], $points[$i][0], $points[$i + 1][1], $points[$i + 1][0]);
     }
     return $bearing / sizeof($points) - 1;
 }
Esempio n. 3
0
    $stops[] = $item;
}
$routes = array();
foreach ($stops as $stop) {
    if (strpos($stop['Route'], 'N') !== 0) {
        $routes[$stop['Route']][$stop['Run']][(int) $stop['Order']] = array('Latitude' => $stop['Latitude'], 'Longitude' => $stop['Longitude']);
    }
}
$distances = array();
$items = array();
foreach ($routes as $route_id => $runs) {
    foreach ($runs as $run_id => $stops) {
        ksort($stops);
        $first = array_slice($stops, 0, 1);
        $last = array_slice($stops, -1, 1);
        $bearing = bearing($first[0]['Latitude'], $first[0]['Longitude'], $last[0]['Latitude'], $last[0]['Longitude']);
        $diff = sqrt(pow($bearing - $mybearing, 2));
        if ($diff > 45) {
            continue;
        }
        $distances[$route_id] = distance($first[0]['Latitude'], $first[0]['Longitude'], $last[0]['Latitude'], $last[0]['Longitude']);
        $items[$route_id] = $stops;
    }
}
// TODO: fix the distance function and make sure sorting works - longest first
uksort($items, function ($a, $b) use($distances) {
    return $distances[$a] > $distances[$b];
});
print json_encode(array('center' => $center, 'radius' => $radius, 'stops' => $items));
function bearing($lat1, $long1, $lat2, $long2)
{