Subscribe to a Premium Development Newsletter by TheDevCouple! What is TheDevTakeaway?

It is quite important for content creators, course makers to know from where their audience is coming from. There are different kinds of products available on the Internet just for this purpose. Most of these products are paid and cost too much. They also need maintainability. 

During this time, there is still a product out there which provides you all this information and more for a price of $0. It not only allows you to get your customer’s location but also provides a whole lot of other information about that location like currency, country code, continent, etc. The product I am talking about is the IP Geolocation API.

In this piece, I am going to share with you my two cents about working with this API. How it works and what kind of information it provides. So without any further delay, let’s jump in! 🙌🏻

Cover Thedevcouple

📍 IP Geolocation API

IP Geolocation API is a child company of API Layer which was founded by Paul Zehetmayr in 2015. Since the launch of API Layer, it has come a long way and provides many amazing products like ipstack and ipapi, etc. Among these products lies the IP Geolocation API that is a free real-time IP to Geolocation JSON API with detailed countries data integration. 

IP Geolocation API provides you with the geolocation of a user. Geolocation is the identification or estimation of the real-world geographic location of an internet-connected computer or device. This API also provides country information packaged as convenient JSON objects. This country information includes data from ISO 3166 (countries and states/subdivisions ), ISO 4217 (currency), and last but not the least E.164 (phone number). 💯

Ipgeolocation Thedevcouple

💻 Experimenting With The API

Now it’s time for me to show you how this API works. Just follow the steps below and you are good to go!

→ Step #1

The first thing you need to do is to open the IP Geolocation API website. Once you have opened the site, scroll down to the Usage, and get your desired API endpoint. I am using the API with a geolocate endpoint to get data of the country I am living in right now. 

Usage Thedevcouple

→ Step #2

The next step is to write a simple program to hit the API. I am using JavaScript to make the API call. You can see the program below. Just copy it in your JavaScript file and run it by typing node yourfilename.js. I have also included the response you will receive in the gist below. ⚡️

// importing axios in the file
const axios = require('axios');

// an asychronous function to make the API call
(async () => {
    await axios
        .get('https://api.ipgeolocationapi.com/geolocate')
        .then(({ data }) => console.log(data))
        .catch((err) => console.log(err));
})();

/* Response

{ continent: 'Asia',
  alpha2: 'PK',
  alpha3: 'PAK',
  country_code: '92',
  international_prefix: '00',
  ioc: 'PAK',
  gec: 'PK',
  name: 'Pakistan',
  national_destination_code_lengths: [ 2 ],
  national_number_lengths: [ 9, 10 ],
  national_prefix: '0',
  number: '586',
  region: 'Asia',
  subregion: 'Southern Asia',
  world_region: 'APAC',
  un_locode: 'PK',
  nationality: 'Pakistani',
  postal_code: true,
  unofficial_names: [ 'Pakistan', 'Paquistán', 'パキスタン' ],
  languages_official: [ 'en', 'ur' ],
  languages_spoken: [ 'en', 'ur' ],
  geo:
   { latitude: 30.375321,
     latitude_dec: '29.923219680786133',
     longitude: 69.345116,
     longitude_dec: '69.35774230957031',
     max_latitude: 37.084107,
     max_longitude: 77.8316195,
     min_latitude: 23.6344999,
     min_longitude: 60.8729721,
     bounds: { northeast: [Object], southwest: [Object] } },
  currency_code: 'PKR',
  start_of_week: 'monday' }

*/

🎩 API Features

After I made the API call to the IP Geolocation API, I received a JSON object with geolocation information about myself. I am going to discuss each of these pieces of information in detail now.

  • 🌎 Continent: This shows you from which continent the user is accessing your website or using your product. 
  • 🚀 Alpha2 & Alpha3: The next thing you will see is alpha2 and alpha3. These are ISO standards and two letters and three letters country name code. The response I received was PK and PAK since I am residing in Pakistan. You can see a list of these codes here.
  • 📞 Country Code: IP Geolocation API also provides you with the country code of the user visiting your website or product. The country code is the code you use before making a phone call to an international cell number. 
  • ☎️ International Prefix: An international prefix is a telephone dialing code used to dial out of the country when making an international call. It is also called the international access code. This is done to avoid confusing the country code with the first few digits of a local phone number.
  • 💡 International Olympic Committee (IOC): IOC is the three-letter abbreviation of the country code for the Olympic participants. Since I am in Pakistan, the API gave me a PAK response when I made the API call.
  • 💥 General Embargoed Countries (GEC): Just like IOC, GEC is also a country abbreviation but with two letters.
  • 🔥 Name: The information gives you the name of the country your user is visiting your website or product. You can use this information on a product website to offer a different percentage of the discount.
  • ⚡️ National Destination Code Length: This is the length of the national destination code. The National destination code identifies the number plan area that is to be used by the user.
  • ✆ National Prefix: This is the digit or a combination of digits that must be dialed before an area code when dialing a call to a subscriber from inside his own country but outside his own numbering area.
  • 🌐 Region: This is the area of the world from where your user is accessing your product. Since I am in Asia, I received Asia in response.
  • 🌍 Subregion: IP Geolocation API also provides you with a more precise location of your user. I am in Pakistan which is in Southern Asia. 
  • 🌎 World Region: A world region is a large primary division of the world primarily used in higher education like anthropology, geography, and history. I get the APAC as a response which stands for the Asia Pacific region of the world.
  • 🚝 UN/Locode: This is the United National Code for trade and transport Locations. It is a geographic coding scheme developed and maintained by the United Nations Economic Commission for Europe.
  • 🇨🇦🇦🇺 Nationality: It is the nationality of the user which is accessing your product embedded with this API or hitting it directly. It is not always true since if an American is living in Germany and hitting the API, it will get german as his nationality. 
  • ✉️ Postal Code: If the postal code exists for the country you are living in, you will get true. Otherwise, you will get false.
  • ⚠️ Unofficial Name: This is an array that contains the unofficial names of your country. You can see in the response above that for Pakistan, there are three unofficial names.
  • 📢 Languages Official: This is also an array that contains the language code of the official languages of the country you are living in while making the API call.
  • 🗣 Languages Spoken: This array includes the languages spoken in your country. The response I received had two languages, i.e., Urdu and English.
  • 📌 Geo: Geo is an object which contains the latitudes and longitudes of your country. These coordinates can help you to pinpoint the location of your user.
  • 💰 Currency Code: Every country has a currency. For instance, for the United States for America, it is dollars. For England, it is the pound. This piece of information shows you the currency code of the country from where your user is visiting your website.
  • 📆 Start Of Week: It is self-explanatory. This information will tell you what’s the start of the week in the country where the user is visiting.

🔗 API Endpoints

IP Geolocation API provides its users with different endpoints which they can use to get the desired information they need. Currently, they provide four different endpoints. I am now going to discuss each of them in detail now.

📍 Geolocate

When you make the API call using this endpoint, you will get the information about the country from where you are making the call. This is useful for geolocating users in the frontend without the need to detect their actual IP yourself.

GET https://api.ipgeolocationapi.com/geolocate HTTP/1.1

I have already added the response in the gist above. Just scroll up and take a look!

🔥 Geolocating With IPv4 or IPv6

This endpoint will help you to geolocate any IPv4 or IPv6. For instance, if you have an IP and need a complete geo analysis, you can use this API to make that happen.

GET https://api.ipgeolocationapi.com/geolocate/91.213.103.0 HTTP/1.1

You will get a response something like this one.

{ continent: 'Europe',
  address_format:
   '{{recipient}}\n{{street}}\n{{postalcode}} {{city}}\n{{country}}',
  alpha2: 'DE',
  alpha3: 'DEU',
  country_code: '49',
  international_prefix: '00',
  ioc: 'GER',
  gec: 'GM',
  name: 'Germany',
  national_destination_code_lengths: [ 2, 3, 4, 5 ],
  national_number_lengths: [ 6, 7, 8, 9, 10, 11 ],
  national_prefix: '0',
  number: '276',
  region: 'Europe',
  subregion: 'Western Europe',
  world_region: 'EMEA',
  un_locode: 'DE',
  nationality: 'German',
  eu_member: true,
  eea_member: true,
  vat_rates:
   { standard: 19,
     reduced: [ 7 ],
     super_reduced: null,
     parking: null },
  postal_code: true,
  unofficial_names:
   [ 'Germany',
     'Deutschland',
     'Allemagne',
     'Alemania',
     'ドイツ',
     'Duitsland' ],
  languages_official: [ 'de' ],
  languages_spoken: [ 'de' ],
  geo:
   { latitude: 51.165691,
     latitude_dec: '51.20246505737305',
     longitude: 10.451526,
     longitude_dec: '10.382203102111816',
     max_latitude: 55.0815,
     max_longitude: 15.0418962,
     min_latitude: 47.2701115,
     min_longitude: 5.8663425,
     bounds: { northeast: [Object], southwest: [Object] } },
  currency_code: 'EUR',
  start_of_week: 'monday' }

🇻🇬 Countries

If you are interested in getting information about all the countries in the world, you can then use this endpoint. All you need to do is make an API call to it and save the result in a variable and you are good to go.

GET https://api.ipgeolocationapi.com/countries HTTP/1.1

I am not going to display the information you will receive here. It is because the information is about 195 countries which are too long to display. 

🎩 Geolocating With Country Code 

Earlier I discussed Alpha2 which is an ISO standard. You can use these codes to get information about any country you like. 

GET https://api.ipgeolocationapi.com/countries/de HTTP/1.1

You will get this response if you hit this endpoint. 💯

{ continent: 'North America',
  address_format:
   '{{recipient}}\n{{street}}\n{{city}} {{region_short}} {{postalcode}}\n{{country}}',
  alpha2: 'US',
  alpha3: 'USA',
  country_code: '1',
  international_prefix: '011',
  ioc: 'USA',
  gec: 'US',
  name: 'United States of America',
  national_destination_code_lengths: [ 3 ],
  national_number_lengths: [ 10 ],
  national_prefix: '1',
  number: '840',
  region: 'Americas',
  subregion: 'Northern America',
  world_region: 'AMER',
  un_locode: 'US',
  nationality: 'American',
  postal_code: true,
  unofficial_names:
   [ 'United States',
     'Vereinigte Staaten von Amerika',
     'États-Unis',
     'Estados Unidos',
     'アメリカ合衆国',
     'Verenigde Staten' ],
  languages_official: [ 'en' ],
  languages_spoken: [ 'en' ],
  geo:
   { latitude: 37.09024,
     latitude_dec: '39.44325637817383',
     longitude: -95.712891,
     longitude_dec: '-98.95733642578125',
     max_latitude: 71.5388001,
     max_longitude: -66.885417,
     min_latitude: 18.7763,
     min_longitude: 170.5957,
     bounds: { northeast: [Object], southwest: [Object] } },
  currency_code: 'USD',
  start_of_week: 'sunday' }

🔥 Performance

Now let’s talk about the performance of IP Geolocation API. A geolocation API performance and response time are extremely important especially if you are using it on your website to show country-specific content. 

I am using Postman for this performance test. I have run several tests with different country codes and IP addresses. The following is the result I acquired. These results are the average of many tests I performed.

💡

  • ⚡️ On the first test, I received a response time of 197ms which is pretty impressive.
  • 🚀 I then tested for different alpha2 codes and the response time never went above 200ms.

200ms is blazing fast. IP Geolocation API has ensured that you don’t face any downtime while using their API.

Performance Thedevcouple

📖 Documentation

IP Geolocation API does not provide any documentation of its API and endpoints. This is one of the downsides I saw while I was using it. I had to google many of the response features. It would be extremely helpful for the users of this API if they have some kind of guide that will help them understand the information they are receiving from the API.

🙌🏻 Wrapping Up

I must say this is an extremely powerful free tool for getting geolocation of customers. It has made the lives of so many developers easier by providing the geolocate endpoint to identify their user’s location. It is also lightning fast and ensures that you get your desired results in time without any lag.

The one thing which I found lacking was the documentation which I mentioned above. I am sure that if IP Geolocation API covers this part of the product too then their API will be a huge success. 

Have you used the IP Geolocation API or similar tool before? Which service did you use and how was your experience? Let us know your thoughts in the comments section below.

Peace! 🤞

🙌

SUBSCRIBE TO DEVELOPERS TAKEAWAY!

A Premium Development Newsletter by TheDevCouple! What is TheDevTakeaway?

IPStack #1 Choice for Site Visitors’ Tracking and Identification DevKinsta – One Suite For All Your WordPress Development IPWhoIs.io Review – Get User Location Data In An Instant
There are currently no comments.

🙌 You must have something to say here...