Geocoder\Provider\BingMaps::reverse PHP Method

reverse() public method

{@inheritDoc}
public reverse ( $latitude, $longitude )
    public function reverse($latitude, $longitude)
    {
        if (null === $this->apiKey) {
            throw new InvalidCredentials('No API key provided.');
        }
        $query = sprintf(self::REVERSE_ENDPOINT_URL, $latitude, $longitude, $this->apiKey);
        return $this->executeQuery($query);
    }

Usage Example

Beispiel #1
0
 public function testReverseWithRealCoordinatesReturnsSingleResult()
 {
     if (!isset($_SERVER['BINGMAPS_API_KEY'])) {
         $this->markTestSkipped('You need to configure the BINGMAPS_API_KEY value in phpunit.xml');
     }
     $provider = new BingMaps($this->getAdapter($_SERVER['BINGMAPS_API_KEY']), $_SERVER['BINGMAPS_API_KEY']);
     $results = $provider->reverse(48.86321648955345, 2.3887719959020615);
     $this->assertInstanceOf('Geocoder\\Model\\AddressCollection', $results);
     $this->assertCount(1, $results);
     /** @var \Geocoder\Model\Address $result */
     $result = $results->first();
     $this->assertInstanceOf('\\Geocoder\\Model\\Address', $result);
     $this->assertEquals(48.86321648955345, $result->getLatitude(), '', 0.0001);
     $this->assertEquals(2.3887719959020615, $result->getLongitude(), '', 0.0001);
     $this->assertTrue($result->getBounds()->isDefined());
     $this->assertEquals(48.859353771983, $result->getBounds()->getSouth(), '', 0.0001);
     $this->assertEquals(2.3809437325833, $result->getBounds()->getWest(), '', 0.0001);
     $this->assertEquals(48.867079207124, $result->getBounds()->getNorth(), '', 0.0001);
     $this->assertEquals(2.3966002592208, $result->getBounds()->getEast(), '', 0.0001);
     $this->assertNull($result->getStreetNumber());
     $this->assertEquals('10 Avenue Gambetta', $result->getStreetName());
     $this->assertEquals(75020, $result->getPostalCode());
     $this->assertEquals('Paris', $result->getLocality());
     $this->assertCount(2, $result->getAdminLevels());
     $this->assertEquals('Paris', $result->getAdminLevels()->get(2)->getName());
     $this->assertEquals('IdF', $result->getAdminLevels()->get(1)->getName());
     $this->assertEquals('France', $result->getCountry()->getName());
     $this->assertEquals('FR', $result->getCountry()->getCode());
     $this->assertNull($result->getTimezone());
 }