コード例 #1
0
 /**
  * Get distance from another position
  *
  * @param PositionAbstract $position Position to get distance from.
  *
  * @param string $units Units to return. Default (m) is miles.
  * n = nautical miles, k = kilometers,
  * f = feet, i = inches.
  *
  * @param float $adjustment Adjust the distance to take turns into account.
  * 1.125 seems to be the most accurate.
  *
  * @return float Distance in the specified units
  */
 public function getDistanceFrom(PositionAbstract $position, $units = 'm', $adjustment = 1.125)
 {
     $miles = $adjustment * 3959 * acos(cos(deg2rad($this->getLat())) * cos(deg2rad($position->getLat())) * cos(deg2rad($this->getLng()) - deg2rad($position->getLng())) + sin(deg2rad($this->getLat())) * sin(deg2rad($position->getLat())));
     switch (strtolower($units)) {
         case 'k':
             // kilometers
             return $miles * 1.609344;
             break;
         case 'n':
             // nautical mile
             return $miles * 0.868976242;
             break;
         case 'f':
             // feet
             return $miles * 5280;
             break;
         case 'i':
             // inches
             return $miles * 63360;
             break;
         case 'm':
         default:
             return $miles;
             break;
     }
 }
コード例 #2
0
ファイル: Rectangle.php プロジェクト: he--/PHPGoogleMaps
 /**
  * Constructor
  *
  * @param string|PositionAbstract $southwest Southwest point of the rectangle
  * @param string|PositionAbstract $northeast Northeast point of the rectangle
  * @param array $options Array of rectangle options {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#RectangleOptions}
  * @return Rectangle
  */
 public function __construct($southwest, $northeast, array $options = null)
 {
     if ($southwest instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->southwest = $southwest->getLatLng();
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($southwest, true);
         if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->southwest = $geocode_result;
         } else {
             throw new \PHPGoogleMaps\Core\GeocodeException($geocode_result);
         }
     }
     if ($northeast instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->northeast = $northeast->getLatLng();
     } else {
         $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($northeast, true);
         if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->northeast = $geocode_result;
         } else {
             throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
         }
     }
     if ($options) {
         unset($options['map'], $options['bounds']);
         $this->options = $options;
     }
 }
コード例 #3
0
ファイル: Directions.php プロジェクト: deerob/PHP-Google-Maps
 /**
  * Add a waypoint
  *
  * @param string|PositionAbstract $waypoint The waypoint
  * @param boolean $stopover
  */
 public function addWaypoint($waypoint, $stopover = true)
 {
     if ($waypoint instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->request_options['waypoints'][] = array('location' => $waypoint->getLatLng());
     } else {
         if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($waypoint, true)) instanceof \PHPGoogleMaps\Core\PositionAbstract) {
             $this->request_options['waypoints'][] = array('location' => $geocode_result->getLatLng());
         } else {
             throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result);
         }
     }
 }
コード例 #4
0
ファイル: Map.php プロジェクト: deerob/PHP-Google-Maps
 /**
  * Set map center
  *
  * @param string|PositionAbstract $center Location of the center. Can be a
  *                                location or an object that extends PositionAbstract.
  * @return boolean
  */
 public function setCenter($center)
 {
     if ($center instanceof \PHPGoogleMaps\Core\PositionAbstract) {
         $this->center = $center->getLatLng();
         return true;
     }
     $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode((string) $center);
     if ($geocode_result instanceof \PHPGoogleMaps\Service\GeocodeResult) {
         $this->center = $geocode_result->getLatLng();
         return true;
     }
     return false;
 }