Beispiel #1
0
 public function getDistanceTo(MapLocation $location)
 {
     $earthRadius = 3958.75;
     $dLat = deg2rad($location->getLatitude() - $this->getLatitude());
     $dLng = deg2rad($location->getLongitude() - $this->getLongitude());
     $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($this->getLatitude())) * cos(deg2rad($location->getLatitude())) * sin($dLng / 2) * sin($dLng / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $dist = $earthRadius * $c;
     // from miles
     $meterConversion = 1609;
     $geopointDistance = $dist * $meterConversion;
     return $geopointDistance;
 }
Beispiel #2
0
 /**
  * @param MapLocation|null $location
  */
 public function setLocation($location)
 {
     if ($location instanceof MapLocation) {
         $this->latitude = $location->getLatitude();
         $this->longitude = $location->getLongitude();
     }
 }