I have configured below details in as per my maxmind account. I am using web services client in order to fetch location(country/state/city) based on IP
UserID - maxmind account userid
License Key - maxmind account license key
Host - geoip.maxmind.com
I am referring your WebService example in User Guide. Below is the code in my simple GeoIP module controller. It is not giving me any output when I run the code
<?php
namespace Namespace\Modulename\Controller\Index;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
use Tobai\GeoIp2\Model\WebService\ClientFactory;
class Index extends \Magento\Framework\App\Action\Action
{
protected $resultPageFactory;
protected $clientFactory;
public function __construct(Context $context, PageFactory $pageFactory, ClientFactory $clientFactory)
{
$this->clientFactory = $clientFactory;
$this->resultPageFactory = $pageFactory;
parent::__construct($context);
}
public function execute()
{
$client = $this->clientFactory->create();
$record = $client->city('128.101.101.101');
print($record->country->isoCode . "\n");
print($record->country->name . "\n");
print($record->country->names['zh-CN'] . "\n");
print($record->mostSpecificSubdivision->name . "\n");
print($record->mostSpecificSubdivision->isoCode . "\n");
print($record->city->name . "\n");
print($record->postal->code . "\n");
print($record->location->latitude . "\n");
print($record->location->longitude . "\n");
}
}
I even tried declaring API settings as below but it do not seem to work
Fatal error: Uncaught Error: Class 'GeoIp2\WebService\Client' not found in /Tobai/GeoIp2/Model/WebService/ClientFactory.php:46
The document says
To use this API, you must create a new \GeoIp2\WebService\Client object with your $accountId and $licenseKey, then you call the method corresponding to a specific end point, passing it the IP address you want to look up.
How do I use GeoIP2 WebService example with above code? Am I missing out anything in terms of implementation?
Hi,
I have configured below details in as per my maxmind account. I am using web services client in order to fetch location(country/state/city) based on IP
I am referring your WebService example in User Guide. Below is the code in my simple GeoIP module controller. It is not giving me any output when I run the code
I even tried declaring API settings as below but it do not seem to work
In the file Tobai/GeoIp2/Model/WebService/ClientFactory.php, when I print $client, it returns nothing
On further inspection, it throws below exception
Fatal error: Uncaught Error: Class 'GeoIp2\WebService\Client' not found in /Tobai/GeoIp2/Model/WebService/ClientFactory.php:46
The document says
To use this API, you must create a new \GeoIp2\WebService\Client object with your $accountId and $licenseKey, then you call the method corresponding to a specific end point, passing it the IP address you want to look up.
How do I use GeoIP2 WebService example with above code? Am I missing out anything in terms of implementation?
Thanks