ip2location_api
A light weight wrapper that provides a Drupal Service interface to the IP2Location API
Features
This module provides a service that wraps the IP2Location api via the PHP library ip2location/ip2location-io-php - currently only Geolocation is implemented. There are two helper functions to return the country code and country name.
Post-Installation
- Set up an API key at https://www.ip2location.com
- Save the key at admin/config/system/keys/add as Key Type "IP2 Location API Key"
- Select the key at admin/config/system/ip2location-settings
After these steps you have access to a Drupal Service in code. The service provides the ability to Geolocate the current request, or specify an IP address to Geolocate.
Additional Requirements
You will need to sign up to IP2Location and get an api key.
Keys are managed using Drupal module Key.
Recommended modules/libraries
You will need to write custom code to take advantage of this module.
Similar projects
There is an existing project ip2location however this doesn't currently use the API instead it requires on the user downloading the required databases and keeping these up to date.
Community Documentation
Example code:
Assuming you inject this service and saved it as $ip2LocationAPI then
$countryName = $this->ip2LocationAPI->getCountryName();
would get you the country name of the user making the request as processed by the ip2LocationAPI.
Note there is currently no caching of responses beyond a very simple storage on the service itself. Ideally we'd cache response data so we wouldn't make repeated attempts to look up the same IP address.