IP Geolocation is a way of identifying the geographical location of an IP address. Given that routing of all Internet traffic begins from an originating IP address, sometimes it becomes necessary to identify the originating geographical location of the traffic. If you are new to APIs, you can get up and running quickly with our article titled What is an API?
geoPlugin IP Geolocation API is one of the oldest and most robust API for providing IP geolocation services. In this tutorial, we are going to learn about how to geolocate IP addresses with this API and evaluate some use cases.
If you haven’t done it yet, then sign up for your Rakuten RapidAPI account to get your universal API key to access the GepPlugin Geolocation API and thousands of other APIs hosted on Rakuten Rapid API.
Table of Contents
Applications of IP Geolocation
The Internet lets people live in a virtual world. However, this virtual world is associated with our physical world in every sense. If you think of booking a cab through Uber or ordering groceries online, all these virtual experiences have a link with the physical world around you. In that context, IP geolocation becomes an essential part of tracing an Internet user back to his physical location, either for providing services linked to the user’s geographical location or for law enforcement purposes.
There are two important use cases for an IP Geolocation API.
Your website gets visitors from all across the world. If you want to tweak your website to show location-specific content, then you need to know the location of the visitor’s IP address. Typically, this IP address belongs to the IP address of the visitors’ Internet Service Provider (ISP) in his home country. You can then show region-specific content to the visitor or personalize the content based on the local language.
Ecommerce websites regularly use this strategy to woo customers. Amazon senses the user’s location at the time of the first visit. Based on the user’s home country, they provide suggestions to redirect to Amazon’s country-specific site, which then displays the product prices in local currency.
Hackers routinely attack websites. Popular websites are even more vulnerable to targeted attacks from specific regions of the world. In such cases, it becomes imperative to put policing rules for visitors based on their country of origin. IP geolocation helps you achieve this by analyzing the IP addresses of the visitors.
Wordfence is a popular WordPress plugin that provides a site-wide firewall for WordPress websites. It can detect invalid login attempts from a specific IP address and blocks all traffic from specific countries if too many invalid logins are detected from IP addresses originating in those countries.
Overview of geoPlugin IP Geolocation API
Let’s look at the geoPlugin IP Geolocation API in more detail.
Log in to your Rakuten RapidAPI and search for “geoplugin”.
You can also access the API console directly by clicking here.
The API supports two endpoint categories, “IP Geolocation” and “Currency Conversion”. You can check the “Pricing” tab and subscribe to the free basic plan.
The basic plan allows you to access only the “IP Geolocation” endpoints to geolocation IP addresses. The “Currency Conversion” endpoints are available only in the paid plans.
Our focus for this tutorial is on the “IP Geolocation” endpoints. Expand the “IP Geolocation” category, and you can see all the options.
For most applications, the “JSON IP geolocation” endpoint suffices your requirements. It returns the location-specific details for an IP address.
Testing the geoPlugin IP Geolocation API
Get ready for a test run now. Select the “JSON IP Geolocation” from the endpoints panel at the left, and hit the “Test Endpoint” button.
By default, the endpoint does not take any input and accepts the IP address of your computer as the default input. Here is the API response if we set the ‘íp’ parameter to a value of “22.214.171.124”, which is one of Google’s servers located in the US.
The response includes essential details about the origin of the IP address, such as the continent name, country name, state name as well as the city. It should provide you enough information to segment the visitors based on their location.
In case you are looking to offer content in a regional language, then based on the country, you can redirect them to the country-specific website.
For traffic policing based on the location, you can block access to your website for the visitors coming from specific regions. It can be work in other ways as well. For example, when you are hosting a collaborative chat application for a specific country, you allow only those people from that country to join the chat room.
You can try out the other endpoints to retrieve the API response in specific formats. For instance, the “CSV IP geolocation” endpoint returns the same result in the CSV (Comma Separated Values” format, which is suitable for logging purposes.
The geoPlugin IP Geolocation is simple and easy to use API. It is one of the best IP geolocation APIs out there. In case you are curious about the “Currency Conversion”, it is precisely what it sounds like. This endpoint converts a given amount from one currency from another. It can help you display location-specific pricing tables for your product based on the country of origin.
In this way, both the “IP Geolocation” and “Currency Conversion” endpoint can work in tandem to provide a seamless localized experience to visitors coming to your eCommerce website by presenting products available for the users’ location along with price options in the local currency.
If you are looking for more options, then take a look at our Top 10 Best IP Geolocation APIs.
We will be back soon with an API tutorial on one of our popular APIs.