Example #1
0
 /**
  * 
  * @param EGMapCoord $gmap_coord
  * @return boolean $is_inside
  * @author fabriceb
  * @since Jun 2, 2009 fabriceb
  */
 public function containsEGMapCoord(EGMapCoord $gmap_coord)
 {
     $is_inside = $gmap_coord->getLatitude() < $this->getNorthEast()->getLatitude() && $gmap_coord->getLatitude() > $this->getSouthWest()->getLatitude() && $gmap_coord->getLongitude() < $this->getNorthEast()->getLongitude() && $gmap_coord->getLongitude() > $this->getSouthWest()->getLongitude();
     return $is_inside;
 }
Example #2
0
 /**
  * exact distance with Haversine formula
  *
  * @param EGMapCoord $coord2
  * @return float
  * @see http://www.movable-type.co.uk/scripts/latlong.html
  *
  * @author fabriceb
  * @since Apr 21, 2010
  */
 public function exactDistanceFrom($coord2)
 {
     $lat1 = deg2rad($this->getLatitude());
     $lat2 = deg2rad($coord2->getLatitude());
     $lon1 = deg2rad($this->getLongitude());
     $lon2 = deg2rad($coord2->getLongitude());
     $dLatHalf = ($lat2 - $lat1) / 2;
     $dLonHalf = ($lon2 - $lon1) / 2;
     $a = pow(sin($dLatHalf), 2) + cos($lat1) * cos($lat2) * pow(sin($dLonHalf), 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return $c * self::EARTH_RADIUS;
 }