Geocoder\Provider\FreeGeoIp::geocode PHP Method

geocode() public method

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

Usage Example

Esempio n. 1
0
 public function testGeocodeWithUKIPv6()
 {
     $provider = new FreeGeoIp($this->getAdapter());
     $results = $provider->geocode('::ffff:129.67.242.154');
     $this->assertInstanceOf('Geocoder\\Model\\AddressCollection', $results);
     $this->assertCount(1, $results);
     $this->assertEquals('GB', $results->first()->getCountry()->getCode());
 }