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
 public function testGivenCoordinateAndRadius_parserReturnsCircle()
 {
     $parser = new CircleParser();
     $circle = $parser->parse('57.421,23.90625:32684.605182');
     $this->assertInstanceOf('Maps\\Elements\\Circle', $circle);
     $expectedLatLong = new LatLongValue(57.421, 23.90625);
     $this->assertTrue($expectedLatLong->equals($circle->getCircleCentre()));
     $this->assertEquals(32684.605182, $circle->getCircleRadius());
 }
Ejemplo n.º 4
0
 public function testGivenBoundingBox_parserReturnsRectangle()
 {
     $parser = new RectangleParser();
     $rectangle = $parser->parse('51.8357775,33.83789:46,23.37890625');
     $this->assertInstanceOf('Maps\\Elements\\Rectangle', $rectangle);
     $expectedNorthEast = new LatLongValue(51.8357775, 33.83789);
     $this->assertTrue($expectedNorthEast->equals($rectangle->getRectangleNorthEast()));
     $expectedSouthWest = new LatLongValue(46, 23.37890625);
     $this->assertTrue($expectedSouthWest->equals($rectangle->getRectangleSouthWest()));
 }
Ejemplo n.º 5
0
 /**
  * @since 3.0
  *
  * @param LatLongValue $rectangleNorthEast
  * @param LatLongValue $rectangleSouthWest
  *
  * @throws InvalidArgumentException
  */
 public function __construct(LatLongValue $rectangleNorthEast, LatLongValue $rectangleSouthWest)
 {
     if ($rectangleNorthEast->equals($rectangleSouthWest)) {
         throw new InvalidArgumentException('$rectangleNorthEast cannot be equal to $rectangleSouthWest');
     }
     parent::__construct();
     // TODO: validate bounds are correct, if not, flip
     $this->setRectangleNorthEast($rectangleNorthEast);
     $this->setRectangleSouthWest($rectangleSouthWest);
 }
Ejemplo n.º 6
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.º 7
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.º 8
0
 /**
  * @dataProvider latLongValueProvider
  */
 public function testGivenLatLongInConstructor_getCoordinatesReturnsIt(LatLongValue $latLong)
 {
     $location = new Location($latLong);
     $this->assertTrue($latLong->equals($location->getCoordinates()));
 }
Ejemplo n.º 9
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.º 10
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.º 11
0
 /**
  * @dataProvider instanceProvider
  * @param LatLongValue $latLongValue
  * @param array $arguments
  */
 public function testGetLongitude(LatLongValue $latLongValue, array $arguments)
 {
     $actual = $latLongValue->getLongitude();
     $this->assertInternalType('float', $actual);
     $this->assertEquals((double) $arguments[1], $actual);
 }
Ejemplo n.º 12
0
 private function equals(LatLongValue $a, LatLongValue $b)
 {
     return abs($a->getLatitude() - $b->getLatitude()) < self::EPSILON && abs($a->getLongitude() - $b->getLongitude()) < self::EPSILON;
 }