internetdata / geocoder-php-provider
Official InternetData provider for Geocoder PHP. Geolocate an IPv4 or IPv6 address: country with no key, city, region, postal code and coordinates with one.
Package info
github.com/internetdata/sdk-php-geocoder
pkg:composer/internetdata/geocoder-php-provider
Requires
- php: ^8.1
- geocoder-php/common-http: ^4.0
- willdurand/geocoder: ^4.0 || ^5.0
Requires (Dev)
- geocoder-php/provider-integration-tests: ^1.6.3
- php-http/message: ^1.0
- phpunit/phpunit: ^9.6.11
Suggests
None
Provides
Conflicts
None
Replaces
None
README
The official Geocoder PHP provider for the InternetData API.
It geolocates IPv4 and IPv6 addresses. Without a key you get the country and timezone of every address. With a key on a paid plan, or within a free key's trial, you also get the city, region, postal code and coordinates.
Getting Started
composer require internetdata/geocoder-php-provider
Like every Geocoder provider it takes a PSR-18 HTTP client, so bring the one your project already uses, Guzzle or Symfony's for example.
use Geocoder\Query\GeocodeQuery; use GuzzleHttp\Client; use InternetData\Geocoder\InternetData; $provider = new InternetData(new Client()); $address = $provider->geocodeQuery(GeocodeQuery::create('8.8.8.8'))->first(); echo $address->getCountry()->getCode(); // US echo $address->getTimezone(); // America/Los_Angeles
To get the city and coordinates, pass your API key from your dashboard:
$provider = new InternetData(new Client(), getenv('INTERNETDATA_API_KEY')); $address = $provider->geocodeQuery(GeocodeQuery::create('74.125.45.100'))->first(); echo $address->getLocality(); // Tulsa echo $address->getAdminLevels()->get(1)->getName(); // Oklahoma echo $address->getCoordinates()->getLatitude(); // 36.15398
It works with StatefulGeocoder, ProviderAggregator and the Laravel and Symfony bundles like any other provider.
What it answers
| Geocoder field | Without a key | Paid plan or trial |
|---|---|---|
getCountry() code and name |
yes | yes |
getTimezone() |
yes | yes |
getLocality() (city) |
yes | |
getAdminLevels() level 1 (region, with its ISO 3166-2 code) |
yes | |
getPostalCode() |
yes | |
getCoordinates() |
yes |
A private or reserved address, like 10.0.0.1, comes back as an empty collection, and 127.0.0.1 and ::1 as localhost without a request. A street address or a reverse query throws UnsupportedOperation, a wrong key InvalidCredentials and a spent quota QuotaExceeded. Plans and their limits are on the pricing page.
Other Libraries
There are official InternetData client libraries available for many languages including PHP, Python, Go, Java, and Ruby. See our GitHub at https://github.com/internetdata for more.
About InternetData
Geolocation, anonymity, ownership and network data for IP addresses, AS numbers and domains, as an API and as databases you download and query yourself.
License
This project is licensed under the MIT License.