This project is not covered by Drupal’s security advisory policy.
This module helps in integration of IP Address Lookup (https://ipapi.co/#api).
ipapi.co provides a REST API to find the location of an IP address.
Specifically, you can get the following information for any IP address:
city, region (name & code), country (name & code), continent, postal code / zip code, latitude, longitude, timezone, utc offset, european union (EU) membership, country calling code, country capital, country tld (top-level domain), currency (name & code), area & population of the country, languages spoken, asn, organization and hostname*.
When you are using this api on client side, it work perfectly using the public IP.
GET https://ipapi.co/{format}/
Like GET https://ipapi.co/json/
When it comes to use at server side, it start giving response as per server IP
This module helps you in working with client side with some back-end configuration. It provide services which you can easily use in getting IP address details.
Step Involve
- Install module as you do.
- If you have API you can add in the configuration
/admin/config/services/ip_address_lookup - There is also a debug option which you can used to check the response for specifit IP address.
Function to Use
- getCountry() : This will return the Country Name
- getCity() : This will return the City Name
- getCountryCode() : This will return the Country Code
- getRegion() : Get region/state short code (FIPS or ISO)
- getLatitude() : Get latitude
- getLongitude() : Get longitude.
- getPostal() : Get zip/Postal code.
- getTimezone() : Get timezone
How to use service in code
- getCountry()
$country = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountry(); - getCity()
$city = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCity(); - getCountryCode()
$country_code = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountryCode(); - getRegion()
$region = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getRegion(); - getLatitude()
$lat = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLatitude(); - getLongitude()
$long = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLongitude(); - getPostal()
$postal = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getPostal(); - getTimezone()
$timezone = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getTimezone();
If you want to get all data together then just call
\Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail();
Project information
- Project categories: Integrations
- Created by mahtabalam on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.


