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()); }
/** * @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); }
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())); }
/** * 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; }
/** * @dataProvider latLongValueProvider */ public function testGivenLatLongInConstructor_getCoordinatesReturnsIt(LatLongValue $latLong) { $location = new Location($latLong); $this->assertTrue($latLong->equals($location->getCoordinates())); }
/** * 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); }