Beispiel #1
0
 public function getLongitude()
 {
     if (isset($this->geocoderResult) === false) {
         $this->geocodeAddress();
     }
     return $this->geocoderResult->getLongitude();
 }
 /**
  * @dataProvider dataProviderForTestFormat
  */
 public function testFormat($data, $format, $expected)
 {
     $geocodedObject = new Geocoded();
     $geocodedObject->fromArray($data);
     $formatter = new Formatter($geocodedObject);
     $result = $formatter->format($format);
     $this->assertTrue(is_string($result));
     $this->assertEquals($expected, $result);
 }
Beispiel #3
0
 public function testResultInterfaceCoordinate()
 {
     $geocoded = new Geocoded();
     $geocoded->fromArray(array('latitude' => 1, 'longitude' => 2));
     $coordinate = $this->geotools->coordinate($geocoded);
     $this->assertInstanceOf('League\\Geotools\\Coordinate\\Coordinate', $coordinate);
     $this->assertSame(1.0, $coordinate->getLatitude());
     $this->assertSame(2.0, $coordinate->getLongitude());
     $this->assertSame('WGS 84', $coordinate->getEllipsoid()->getName());
 }
 public function testDumpWithProperties()
 {
     $obj = new Geocoded();
     $obj['latitude'] = 48.8631507;
     $obj['longitude'] = 2.3889114;
     $obj->fromArray(array('bounds' => array('south' => 48.8631507, 'west' => 2.3889114, 'north' => 48.8631507, 'east' => 2.388911), 'city' => 'Paris', 'country' => 'France'));
     $expected = array('type' => 'Feature', 'geometry' => array('type' => 'Point', 'coordinates' => array(2.3889114, 48.8631507)), 'properties' => array('city' => 'Paris', 'country' => 'France'), 'bounds' => array('south' => 48.8631507, 'west' => 2.3889114, 'north' => 48.8631507, 'east' => 2.388911));
     $result = $this->dumper->dump($obj);
     $this->assertTrue(is_string($result));
     $this->assertEquals($expected, json_decode($result, true));
 }
 public function testGetAngleWithZeroDistance()
 {
     $geocoded = new Geocoded();
     $geocoded->fromArray(array('latitude' => '47.218371', 'longitude' => '-1.553621'));
     $expected = new Geocoded();
     // 0 km away from $geocoded, in the nortEast direction
     $expected->fromArray(array('latitude' => '47.218371', 'longitude' => '-1.553621'));
     $result = $this->geometry->getAngle($geocoded, 45, 0);
     $this->assertTrue($result instanceof Geocoded);
     $this->assertEquals($expected, $result);
 }
 public function setUp()
 {
     $logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
     $logger->expects($this->any())->method('info')->will($this->returnValue(null));
     $this->geocoderLogger = new GeocoderLogger($logger);
     $this->result = new Geocoded();
     $this->result->fromArray(array('latitude' => 1, 'longitude' => 2));
     $this->results = new \SplObjectStorage();
     $this->results->attach($this->result);
     $otherResult = new Geocoded();
     $otherResult->fromArray(array('latitude' => 3, 'longitude' => 4));
     $this->results->attach($otherResult);
 }
 /**
  * @test
  */
 public function it_returns_coordinates()
 {
     $address = 'Wetstraat 1, 1000 Brussel, BE';
     $latFloat = 1.07845;
     $longFloat = 2.76412;
     $coordinatesArray = ['latitude' => $latFloat, 'longitude' => $longFloat];
     $result = new Geocoded();
     $result->fromArray($coordinatesArray);
     $this->geocoder->expects($this->once())->method('geocode')->with($address)->willReturn($result);
     $expectedCoordinates = new Coordinates(new Latitude($latFloat), new Longitude($longFloat));
     $actualCoordinates = $this->service->getCoordinates($address);
     $this->assertEquals($expectedCoordinates, $actualCoordinates);
 }
 public function defineBoundingBox($lat, $lng, $distance = self::DEFAULT_DISTANCE, $unit = self::DEFAULT_UNIT)
 {
     // the origin
     $geocoded = new Geocoded();
     $geocoded->fromArray(array('latitude' => $lat, 'longitude' => $lng));
     // the boundingbox angles
     $this->southWest = BoundingBoxGeometry::getAngle($geocoded, 225, $distance, $unit);
     $this->northEast = BoundingBoxGeometry::getAngle($geocoded, 45, $distance, $unit);
     // the min/max coords
     $this->minLat = $this->southWest['lat'];
     $this->minLng = $this->southWest['lng'];
     $this->maxLat = $this->northEast['lat'];
     $this->maxLng = $this->northEast['lng'];
     return $this;
 }
 /**
  * getAngle: Get a bounding box angle
  * Determining two angles (southWest & northEast) is sufficient to create a boundinx box
  *
  * @link http://richardpeacock.com/blog/2011/11/draw-box-around-coordinate-google-maps-based-miles-or-kilometers
  * @link http://www.sitepoint.com/forums/showthread.php?656315-adding-distance-gps-coordinates-get-bounding-box
  * @param  ResultInterface $result
  * @param  integer         $bearing
  * @param  float           $distance
  * @param  string          $distance_unit
  * @return Geocoded        A bounding box Angle
  */
 public static function getAngle(Geocoded $result, $bearing, $distance, $distance_unit = "km")
 {
     $geocoded = new Geocoded();
     if ($distance_unit == "m") {
         // Distance is in miles.
         $radius = 3963.1676;
     } else {
         // distance is in km.
         $radius = 6378.1;
     }
     $tuple = array();
     // New latitude in degrees.
     $tuple['latitude'] = rad2deg(asin(sin(deg2rad($result->getLatitude())) * cos($distance / $radius) + cos(deg2rad($result->getLatitude())) * sin($distance / $radius) * cos(deg2rad($bearing))));
     // New longitude in degrees.
     $tuple['longitude'] = rad2deg(deg2rad($result->getLongitude()) + atan2(sin(deg2rad($bearing)) * sin($distance / $radius) * cos(deg2rad($result->getLatitude())), cos($distance / $radius) - sin(deg2rad($result->getLatitude())) * sin(deg2rad($tuple['latitude']))));
     $geocoded->fromArray($tuple);
     return $geocoded;
 }
    public function testDumpWithData()
    {
        $obj = new Geocoded();
        $obj['latitude'] = 48.8631507;
        $obj['longitude'] = 2.3889114;
        $obj->fromArray(array('city' => 'Paris'));
        $expected = <<<KML
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
        <Placemark>
            <name><![CDATA[Paris]]></name>
            <description><![CDATA[Paris]]></description>
            <Point>
                <coordinates>2.3889114,48.8631507,0</coordinates>
            </Point>
        </Placemark>
    </Document>
</kml>
KML;
        $result = $this->dumper->dump($obj);
        $this->assertTrue(is_string($result));
        $this->assertEquals($expected, $result);
    }
Beispiel #11
0
 /**
  * {@inheritDoc}
  */
 public function fromArray(array $data = array())
 {
     parent::fromArray($data);
     if (isset($data['providerName'])) {
         $this->providerName = $this->formatString($data['providerName']);
     }
     if (isset($data['query'])) {
         $this->query = $this->formatString($data['query']);
     }
     if (isset($data['exception'])) {
         $this->exception = $this->formatString($data['exception']);
     }
 }
 public function testFormatNameDoesNotAddUnrecognizedParameters()
 {
     $obj = new Geocoded();
     $obj->fromArray(array('city' => 'Paris', 'country' => 'France', 'foo' => 'foo', 'bar' => 'bar'));
     $expected = 'Paris, France';
     $this->assertEquals($expected, $this->dumper->formatName($obj));
 }
Beispiel #13
0
 /**
  * @param array $data An array of data.
  *
  * @return Geocoded
  */
 protected function returnResult(array $data = array())
 {
     $result = new Geocoded();
     $result->fromArray($data);
     return $result;
 }