コード例 #1
0
 public static function getDistance($p1, $p2)
 {
     $radius = 6378137;
     $dLat = LocationController::rad($p2->latitude - $p1->latitude);
     $dLong = LocationController::rad($p2->longitude - $p1->longitude);
     $a = sin($dLat / 2) * sin($dLat / 2) + cos(LocationController::rad($p1->latitude)) * cos(LocationController::rad($p2->latitude)) * sin($dLong / 2) * sin($dLong / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $d = $radius * $c;
     return $d;
 }