Geocoder\Provider\OpenCage::geocode PHP Méthode

geocode() public méthode

public geocode ( $address )
    public function geocode($address)
    {
        if (null === $this->apiKey) {
            throw new InvalidCredentials('No API Key provided.');
        }
        // This API doesn't handle IPs
        if (filter_var($address, FILTER_VALIDATE_IP)) {
            throw new UnsupportedOperation('The OpenCage provider does not support IP addresses, only street addresses.');
        }
        $query = sprintf(self::GEOCODE_ENDPOINT_URL, $this->scheme, $this->apiKey, urlencode($address), $this->getLimit());
        return $this->executeQuery($query);
    }

Usage Example

 /**
  * @expectedException \Geocoder\Exception\UnsupportedOperation
  * @expectedExceptionMessage The OpenCage provider does not support IP addresses, only street addresses.
  */
 public function testGeocodeWithRealIPv6()
 {
     $provider = new OpenCage($this->getAdapter(), 'api_key');
     $provider->geocode('::ffff:74.200.247.59');
 }