Yii2 component geolocation http://ipgeobase.ru/ service
composer require sem-soft/yii2-ipgeobase
$ ./yii migrate/up --migrationPath=@vendor/sem-soft/yii2-ipgeobase/migrations
Or add this code into require section of your composer.json and then call composer update in console
"sem-soft/yii2-ipgeobase": "*"
In configuration file do
<?php
...
'components' => [
...
'geo' => [
'class' => \sem\ipgeobase\IpGeoBase::className(),
'serviceTimeout' => 2
],
...
],
...
?>
Use as simple component
<?php
if ($g = Yii::$app->geo->geo) {
echo $g->city;
}
if ($g = Yii::$app->geo->getGeo('86.XXX.YYY.ZZZ')) {
echo $g->city;
}
if ($g = Yii::$app->geo->getCityInfo('Москва')) {
echo $g->city;
}
?>