Create a free account on https://www.maxmind.com/en/geolite2/signup
And validate it by following the link in your mailbox
Then generate your licence key https://www.maxmind.com/en/accounts/current/license-key
Then put the value in your .env
or .env.local
GEOIP2_ACCOUNT_ID=123456
GEOIP2_LICENSE_KEY=xxxxxx
In your config/services.yaml
GeoIp2\WebService\Client:
arguments:
$accountId: '%env(int:GEOIP2_ACCOUNT_ID)%'
$licenseKey: '%env(string:GEOIP2_LICENSE_KEY)%'
$locales: ['%kernel.default_locale']
$options:
host: 'geolite.info'
Then you can access the service as you want, ex :
use GeoIp2\WebService\Client;
public function test(Client $client)
{
$record = $client->city();
dump($record->country->isoCode); // 'US'
dump($record->country->name); // 'United States'
dump($record->country->names['zh-CN']); // '美国'
dump($record->mostSpecificSubdivision->name); // 'Minnesota'
dump($record->mostSpecificSubdivision->isoCode); // 'MN'
dump($record->city->name); // 'Minneapolis'
dump($record->postal->code); // '55455'
dump($record->location->latitude); // 44.9733
dump($record->location->longitude); // -93.2323
dump($record->traits->network); // '128.101.101.101/32'
}