Ejemplo n.º 1
0
 /**
  * @param LatLongValue $value
  * @param float $minimumLongitude
  *
  * @return LatLongValue
  */
 public function normalizeLatLong(LatLongValue $value, $minimumLongitude = -180.0)
 {
     $lat = $value->getLatitude();
     $lon = $value->getLongitude();
     // Normalize to [-180°..+180°[ on Earth/Moon, [0°..+360°[ on other globes.
     if ($lon >= $minimumLongitude + 360) {
         $lon -= 360;
     } elseif ($lon < $minimumLongitude) {
         $lon += 360;
     }
     if ($lat >= 270) {
         // Same side of the globe, on the southern hemisphere.
         $lat -= 360;
     } elseif ($lat <= -270) {
         // Same side of the globe, on the northern hemisphere.
         $lat += 360;
     } elseif ($lat > 90) {
         // Other side of the globe
         $lat = 180 - $lat;
         $lon += $lon - 180 >= $minimumLongitude ? -180 : 180;
     } elseif ($lat < -90) {
         // Other side of the globe
         $lat = -180 - $lat;
         $lon += $lon - 180 >= $minimumLongitude ? -180 : 180;
     }
     // North/south pole
     if (abs($lat) === 90.0) {
         $lon = 0;
     }
     return new LatLongValue($lat, $lon);
 }
Ejemplo n.º 2
0
 private function detectPrecision(LatLongValue $latLong, $precisionDetector)
 {
     if ($this->options->hasOption('precision')) {
         return $this->options->getOption('precision');
     }
     return min(call_user_func(array($this, $precisionDetector), $latLong->getLatitude()), call_user_func(array($this, $precisionDetector), $latLong->getLongitude()));
 }
Ejemplo n.º 3
0
 /**
  * Returns the geographical distance between two coordinates.
  * See http://en.wikipedia.org/wiki/Geographical_distance
  * 
  * @since 2.0
  * 
  * @param LatLongValue $start
  * @param LatLongValue $end
  * 
  * @return float Distance in m.
  */
 public static function calculateDistance(LatLongValue $start, LatLongValue $end)
 {
     $northRad1 = deg2rad($start->getLatitude());
     $eastRad1 = deg2rad($start->getLongitude());
     $cosNorth1 = cos($northRad1);
     $cosEast1 = cos($eastRad1);
     $sinNorth1 = sin($northRad1);
     $sinEast1 = sin($eastRad1);
     $northRad2 = deg2rad($end->getLatitude());
     $eastRad2 = deg2rad($end->getLongitude());
     $cosNorth2 = cos($northRad2);
     $cosEast2 = cos($eastRad2);
     $sinNorth2 = sin($northRad2);
     $sinEast2 = sin($eastRad2);
     $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2;
     $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2;
     $term3 = $sinNorth1 - $sinNorth2;
     $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3;
     $distance = 2 * Maps_EARTH_RADIUS * asin(sqrt($distThruSquared) / 2);
     assert($distance >= 0);
     return $distance;
 }
Ejemplo n.º 4
0
 /**
  * Returns an object that can directly be converted to JS using json_encode or similar.
  *
  * FIXME: complexity
  *
  * @since 1.0
  *
  * @param string $defText
  * @param string $defTitle
  * @param string $defIconUrl
  * @param string $defGroup
  * @param string $defInlineLabel
  * @param string $defVisitedIcon
  *
  * @return array
  */
 public function getJSONObject($defText = '', $defTitle = '', $defIconUrl = '', $defGroup = '', $defInlineLabel = '', $defVisitedIcon = '')
 {
     $parentArray = parent::getJSONObject($defText, $defTitle);
     $array = array('lat' => $this->coordinates->getLatitude(), 'lon' => $this->coordinates->getLongitude(), 'alt' => 0, 'address' => $this->getAddress(false), 'icon' => $this->hasIcon() ? \MapsMapper::getFileUrl($this->getIcon()) : $defIconUrl, 'group' => $this->hasGroup() ? $this->getGroup() : $defGroup, 'inlineLabel' => $this->hasInlineLabel() ? $this->getInlineLabel() : $defInlineLabel, 'visitedicon' => $this->hasVisitedIcon() ? $this->getVisitedIcon() : $defVisitedIcon);
     return array_merge($parentArray, $array);
 }
Ejemplo n.º 5
0
 /**
  * @see DataValue::getArrayValue
  *
  * @return array
  */
 public function getArrayValue()
 {
     return array('latitude' => $this->latLang->getLatitude(), 'longitude' => $this->latLang->getLongitude(), 'altitude' => null, 'precision' => $this->precision, 'globe' => $this->globe);
 }
Ejemplo n.º 6
0
 /**
  * Formats a LatLongValue with the desired precision.
  *
  * @since 0.5
  *
  * @param LatLongValue $value
  * @param float $precision The desired precision, given as fractional degrees.
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public function formatLatLongValue(LatLongValue $value, $precision)
 {
     if ($precision <= 0) {
         $precision = 1 / 3600;
     }
     $formatted = implode($this->getOption(self::OPT_SEPARATOR_SYMBOL) . $this->getSpacing(self::OPT_SPACE_LATLONG), array($this->formatLatitude($value->getLatitude(), $precision), $this->formatLongitude($value->getLongitude(), $precision)));
     return $formatted;
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider instanceProvider
  * @param LatLongValue $latLongValue
  * @param array $arguments
  */
 public function testGetLatitude(LatLongValue $latLongValue, array $arguments)
 {
     $actual = $latLongValue->getLatitude();
     $this->assertInternalType('float', $actual);
     $this->assertEquals((double) $arguments[0], $actual);
 }
Ejemplo n.º 8
0
 private function equals(LatLongValue $a, LatLongValue $b)
 {
     return abs($a->getLatitude() - $b->getLatitude()) < self::EPSILON && abs($a->getLongitude() - $b->getLongitude()) < self::EPSILON;
 }