Geocoder\Provider\GeoPlugin::geocode PHP Метод

geocode() публичный Метод

{@inheritDoc}
public geocode ( $address )
    public function geocode($address)
    {
        if (!filter_var($address, FILTER_VALIDATE_IP)) {
            throw new UnsupportedOperation('The GeoPlugin provider does not support street addresses, only IP addresses.');
        }
        if (in_array($address, array('127.0.0.1', '::1'))) {
            return $this->returnResults([$this->getLocalhostDefaults()]);
        }
        $query = sprintf(self::GEOCODE_ENDPOINT_URL, $address);
        return $this->executeQuery($query);
    }

Usage Example

Пример #1
0
 public function testGeocodeWithRealIPv4()
 {
     $provider = new GeoPlugin($this->getAdapter());
     $results = $provider->geocode('66.147.244.214');
     $this->assertInstanceOf('Geocoder\\Model\\AddressCollection', $results);
     $this->assertCount(1, $results);
     $result = $results->first();
     $this->assertEquals(40.711102, $result->getLatitude(), '', 0.0001);
     $this->assertEquals(-73.946899, $result->getLongitude(), '', 0.0001);
     $this->assertNull($result->getLocality());
     $this->assertCount(1, $result->getAdminLevels());
     $this->assertEquals('New York', $result->getAdminLevels()->get(1)->getName());
     $this->assertEquals('NY', $result->getAdminLevels()->get(1)->getCode());
     $this->assertEquals('United States', $result->getCountry()->getName());
     $this->assertEquals('US', $result->getCountry()->getCode());
 }