Get Geolocation Data with IPWHOIS.IO API

There are many advantages to detect user’s information or geolocation data. It helps to improve conversion and better analyse website users. It also helps website owners to provide more relevant content to their users.

Getting geolocation data is always a challenge but thanks to Geolocation APIs which makes things easy to handle. There are many services and APIs which will provides geolocation data but these are too costly and also lacking valuable information. I was very much impressed with IPWHOIS.IO geolocation API that provides extra details about location, timezone and currency.

Also, read:

IPWHOIS.IO geolocation API is used by thousands of developers all around the world. It’s easy to integrate to deliver results in JSON, XML or Newline format. The API is totally free for up to 10,000 requests per month.

Main features:

  • Free to use up to 10,000 requests per month.
  • Provides real-time geolocation data.
  • Simple, Fast and Powerful.
  • Multilingual response.
  • Provides secure data.
  • Awesome pricing for small to large sized websites.
  • Documentation provides code samples in PHP, JavaScript, jQuery, Python, and more.

The URL format for IPWHOIS.IO IP Geolocation API is simple:


http://ipwhois.app/json/{IP}

For example, when make API request with following IP Address 8.8.4.4,

You can easily integrate the IPWHOIS.IO API using any programming language. There are no need to register and get API Key, it’s really very simple to integrate. Here we will integrate the API using PHP and display response data.

We will get the user IP address and make HTTP request to http://ipwhois.app/json/{IP} using PHP CURL and pass IP Address. We will decode the returned response data and display response JSON data.

<?php

$ipAddress = $_SERVER['REMOTE_ADDR'];

$ch = curl_init('http://ipwhois.app/json/'.$ipAddress);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsonData = curl_exec($ch);
curl_close($ch);

$resultData = json_decode($jsonData, true);
var_dump($resultData);

?>

Following geolocation response data will be returned in JSON format:


{
  "ip": "8.8.4.4",
  "success": true,
  "type": "IPv4",
  "continent": "North America",
  "continent_code": "NA",
  "country": "United States",
  "country_code": "US",
  "country_flag": "https://cdn.ipwhois.io/flags/us.svg",
  "country_capital": "Washington",
  "country_phone": "+1",
  "country_neighbours": "CA,MX,CU",
  "region": "New Jersey",
  "city": "Newark",
  "latitude": 40.735657,
  "longitude": -74.1723667,
  "asn": "AS15169",
  "org": "Google LLC",
  "isp": "Google LLC",
  "timezone": "America/New_York",
  "timezone_name": "Eastern Standard Time",
  "timezone_dstOffset": 0,
  "timezone_gmtOffset": -18000,
  "timezone_gmt": "GMT -5:00",
  "currency": "US Dollar",
  "currency_code": "USD",
  "currency_symbol": "$",
  "currency_rates": 1,
  "currency_plural": "US dollars",
  "completed_requests": 0
}

Conclusion

Explained how to integrate IPWHOIS.IO API into your website. If you’re a developer or running a website, you can easily integrate API to get the real-time geolocation data. You can checkout the documentation for more details to use API.

You may also like:

Leave a Reply

Your email address will not be published. Required fields are marked *