A Symfony Bundle for the Maxmind GeoIP2 API

Installs: 262 825

Dependents: 3

Suggesters: 0

Security: 0

Stars: 32

Watchers: 4

Forks: 5

Open Issues: 2


v1.2.0 2020-01-21 12:51 UTC

This package is auto-updated.

Last update: 2020-01-24 15:39:02 UTC


Latest Stable Version PHP from Travis config Build Status Coverage Status Scrutinizer Code Quality StyleCI License

A Symfony Bundle for the Maxmind GeoIP2 API

Bundle for use maxmind/GeoIP2 in Symfony.


Pretty simple with Composer, run:

composer req gpslab/geoip2


Attention! MaxMind changed their policy and user agreements about using their data so old URLs like are no working anymore.

Steps for Migration

  1. Sign up for a MaxMind account (no purchase required)
  2. Login and generate a licence key
  3. Save your licence key
  4. Open download page and find your needed DB edition ID and copy value from first column. GeoIP2 download page
  5. Open your config file with gpslab_geoip params and replace url param by next:{edition_id}&license_key={license_key}&suffix=tar.gz
  • ID - character ID name from first column on download page
  • license_key - your saved licence key
    # URL for download new GeoIP database.
    # You should change {edition_id} and {license_key} in URL to your values.
    url: '{edition_id}&license_key={license_key}&suffix=tar.gz'

    # Path to download GeoIP database.
    # It's a default value. You can change it.
    cache: '%kernel.cache_dir%/GeoLite2-City.mmdb'

    # Get model data in this locale
    # It's a default value. You can change it.
    locales: [ '%locale%' ]


You can get GeoIP2 reader service:

// get a GeoIP2 City model
$record = $this->get('geoip2.reader')->city('');

print($record->country->isoCode . "\n"); // 'US'
print($record->country->name . "\n"); // 'United States'
print($record->country->names['zh-CN'] . "\n"); // '美国'

print($record->mostSpecificSubdivision->name . "\n"); // 'Minnesota'
print($record->mostSpecificSubdivision->isoCode . "\n"); // 'MN'

print($record->city->name . "\n"); // 'Minneapolis'

print($record->postal->code . "\n"); // '55455'

print($record->location->latitude . "\n"); // 44.9733
print($record->location->longitude . "\n"); // -93.2323

For more example see the GeoIP2 library.

Update GeoIP database

Execute command for update database:

php bin/console geoip2:update


This bundle is under the MIT license. See the complete license in the file: LICENSE