Example #1
0
 /**
  * @param Point    $center
  * @param Distance $distance
  *
  * @return BoundingBox
  * @author Maximilian Ruta <*****@*****.**>
  */
 public static function createFromCenterAndDistance(Point $center, Distance $distance)
 {
     $distanceInDegrees = $distance->getInGeographicDegrees() / 2;
     $sw = new Point($center->getLatitude() - $distanceInDegrees, $center->getLongitude() - $distanceInDegrees);
     $ne = new Point($center->getLatitude() + $distanceInDegrees, $center->getLongitude() + $distanceInDegrees);
     return new BoundingBox($sw, $ne);
 }
Example #2
0
 /**
  * @param Point $place1
  * @param Point $place2
  *
  * @return Distance
  * @author Maximilian Ruta <*****@*****.**>
  */
 public static function distance(Point $place1, Point $place2)
 {
     $theta = $place1->getLongitude() - $place2->getLongitude();
     $dist = sin(deg2rad($place1->getLatitude())) * sin(deg2rad($place2->getLatitude())) + cos(deg2rad($place1->getLatitude())) * cos(deg2rad($place2->getLatitude())) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     return new Distance($dist);
 }
Example #3
0
 /**
  * @param Point $point
  * @return float
  *
  * thanks to http://stackoverflow.com/questions/7672759/how-to-calculate-distance-from-lat-long-in-php
  */
 public function getCartographicDistance(Point $point)
 {
     $earthRadius = 3958.75;
     $dLat = deg2rad($point->getLatitude() - $this->latitude);
     $dLng = deg2rad($point->getLongitude() - $this->longitude);
     $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($this->latitude)) * cos(deg2rad($point->getLatitude())) * sin($dLng / 2) * sin($dLng / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $dist = $earthRadius * $c;
     // from miles to km
     $meterConversion = 1.609344;
     $geopointDistance = $dist * $meterConversion;
     return round($geopointDistance, 0);
 }
Example #4
0
 public function getAzimuthToPoint(Point $point2)
 {
     // перевести координаты в радианы
     $lat1 = $this->getLatitude() * M_PI / 180;
     $lat2 = $point2->getLatitude() * M_PI / 180;
     $long1 = $this->getLongitude() * M_PI / 180;
     $long2 = $point2->getLongitude() * M_PI / 180;
     // косинусы и синусы широт и разницы долгот
     $cl1 = cos($lat1);
     $cl2 = cos($lat2);
     $sl1 = sin($lat1);
     $sl2 = sin($lat2);
     $delta = $long2 - $long1;
     $cdelta = cos($delta);
     $sdelta = sin($delta);
     //вычисление начального азимута
     $x = (double) ($cl1 * $sl2) - $sl1 * $cl2 * $cdelta;
     $y = (double) $sdelta * $cl2;
     $z = atan2($y, $x) * 180 / M_PI;
     if ($z < 0) {
         $z += 360;
     }
     return $z;
 }
Example #5
0
File: Point.php Project: jlaso/gps
 public function distanceTo(Point $point) : float
 {
     return Tools::distance($this->getLatitude(), $this->getLongitude(), $point->getLatitude(), $point->getLongitude());
 }