JavaScript
Article
By Michael Wanyoike

GeoIP JSON Example

By Michael Wanyoike

GeoIP is a type of Geolocation software that is used to deduce the geographical location of a person or an object using an IP address. There are a number of free and paid geolocation databases which offer these GeoIP services. Accuracy among these databases generally ranges from country, state, city and up to post code level. This technology is often used for geo marketing, regional pricing, fraud detection and criminal investigation.


July 27th, 2017: This article series was rewritten with up-to-date information and fresh examples.


In this example we will look at an online database, IP-API.com, that returns GeoIP data in JSON format. Simply opening this link http://ip-api.com/json/54.148.84.95 will return the following JSON result:

--ADVERTISEMENT--

{
  "as": "AS16509 Amazon.com, Inc.",
  "city": "Boardman",
  "country": "United States",
  "countryCode": "US",
  "isp": "Amazon",
  "lat": 45.8696,
  "lon": -119.688,
  "org": "Amazon",
  "query": "54.148.84.95",
  "region": "OR",
  "regionName": "Oregon",
  "status": "success",
  "timezone": "America\/Los_Angeles",
  "zip": "97818"
}

To see your own Geolocation data in JSON format, just open this link: http://ip-api.com/json/.

Building an application that utilizes this service is pretty simple. You can take a quick look at the docs to see how to implement callbacks and other features. In the event of an error, the following JSON response will be returned:

{
  "status": "fail",
  "message": "ERROR MESSAGE",
  "query": "IP ADDRESS USED FOR QUERY"
}

You should note that this service is not absolutely free. If you need to perform more than 150 requests per minute you will have to sign up for a pro account.

Also: See more JSON examples.

More:
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account