geocoder-php/geoip2-provider

Geocoder GeoIP2 adapter

Package info

github.com/geocoder-php/geoip2-provider

Homepage

pkg:composer/geocoder-php/geoip2-provider

Statistics

Installs: 932 176

Dependents: 6

Suggesters: 2

Stars: 5

4.4.0 2025-04-15 13:24 UTC

Requires

Suggests

None

Conflicts

None

Replaces

None

MIT 69dc5bc293a302c3e404438a375dae7cbbf1be3c

  • William Durand <william.durand1.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-21 12:01:39 UTC


README

👁 Build Status
👁 Latest Stable Version
👁 Total Downloads
👁 Monthly Downloads
👁 Quality Score
👁 Software License

This is the GeoIP2 provider from the PHP Geocoder. This is a READ ONLY repository. See the main repo for information and documentation.

Install

composer require geocoder-php/geoip2-provider

Usage

The provider requires either a database file, or paid access to the web service.

Using a database file

Both free geolite2 and the paid precision city and country databases are supported.

//Use a Maxmind GeoIP2 Database:
$reader = new \GeoIp2\Database\Reader('/path/to/geolite2.mmdb');

$adapter = new \Geocoder\Provider\GeoIP2\GeoIP2Adapter($reader);
$geocoder = new \Geocoder\Provider\GeoIP2\GeoIP2($adapter);

$address = $geocoder->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('74.200.247.59'))->first();

Using the Precision Web Service (API)

The provider also support the Precision Web Services. Please note that these API are paid, and billed per request.

// Use the Maxmind GeoIP2 API:
$reader = new \GeoIp2\WebService\Client(<account_id>, '<licence_key>');

$adapter = new \Geocoder\Provider\GeoIP2\GeoIP2Adapter($reader);
$geocoder = new \Geocoder\Provider\GeoIP2\GeoIP2($adapter);

$address = $geocoder->geocodeQuery(\Geocoder\Query\GeocodeQuery::create('74.200.247.59'))->first();

Contribute

Contributions are very welcome! Send a pull request to the main repository or report any issues you find on the issue tracker.