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

  1. Install module as you do.
  2. If you have API you can add in the configuration /admin/config/services/ip_address_lookup
  3. There is also a debug option which you can used to check the response for specifit IP address.


Function to Use

  1. getCountry() : This will return the Country Name
  2. getCity() : This will return the City Name
  3. getCountryCode() : This will return the Country Code
  4. getRegion() : Get region/state short code (FIPS or ISO)
  5. getLatitude() : Get latitude
  6. getLongitude() : Get longitude.
  7. getPostal() : Get zip/Postal code.
  8. getTimezone() : Get timezone


How to use service in code

  1. getCountry()
    $country = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountry();
  2. getCity()
    $city = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCity();
  3. getCountryCode()
    $country_code = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getCountryCode();
  4. getRegion()
    $region = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getRegion();
  5. getLatitude()
    $lat = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLatitude();
  6. getLongitude()
    $long = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getLongitude();
  7. getPostal()
    $postal = \Drupal::service('ip_address_lookup.getIpAddressGeolocation')->getIpLocationApiDetail()->getPostal();
  8. 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

Releases