Ahmad Awais

NAVIGATE


SHARE


What Is the Best API for Geolocating an IP Address? [2021]

Ahmad AwaisAhmad Awais

While working on a recent project for a client, I found myself in the need of a good and reasonably reliable Geolocation API to find out more about a user that visits your site.

So, I did a little research for currently available APIs and came up with somewhat an exhaustive list. That is what I plan to share today.

I would use a web service that can return JSON data. Below are all the free
active IP lookup services I could find and the information they return. If you know of any more, then do add a comment below. If you own one, reach out to me through the contact form, I’d love to talk.

JUST A NOTE!

👨‍💻 I’m teaching thousands of devs how to become Node.js CLI Automation, VSCode Power Users, and this site is super fast, isn’t it?! It’s hosted with Kinsta on Google servers

Remember FreeGEOIP.net? Well, it is now called IPStack. It has much better offerings, a good enough free package, and affordable premium packages. IPStack offers so much more inside the API response that has made me not only use IPStack for personal use but I also recommend you to take a look:

Just use this link https://api.ipstack.com/check?access_key=YOUR_ACCESS_KEY with the language of your choice to get all the details for more details, read the documentation →

Returns:#

{
	"ip": "8.8.4.4",
	"type": "ipv4",
	"continent_code": "NA",
	"continent_name": "North America",
	"country_code": "US",
	"country_name": "United States",
	"region_code": "CA",
	"region_name": "California",
	"city": "Mountain View",
	"zip": "94043",
	"latitude": 37.419158935546875,
	"longitude": -122.07540893554688,
	"location": {
		"geoname_id": 5375480,
		"capital": "Washington D.C.",
		"languages": [
			{
				"code": "en",
				"name": "English",
				"native": "English"
			}
		],
		"country_flag": "https://assets.ipstack.com/flags/us.svg",
		"country_flag_emoji": "🇺🇸",
		"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
		"calling_code": "1",
		"is_eu": false
	},
	"time_zone": {
		"id": "America/Los_Angeles",
		"current_time": "2020-12-10T03:32:54-08:00",
		"gmt_offset": -28800,
		"code": "PST",
		"is_daylight_saving": false
	},
	"currency": {
		"code": "USD",
		"name": "US Dollar",
		"plural": "US dollars",
		"symbol": "$",
		"symbol_native": "$"
	},
	"connection": {
		"asn": 15169,
		"isp": "Google LLC"
	}
}

Pros:#

Limitations:#

Remember GeoIP Nekudo that used to require an IP Address parameter? Well, it is now ipapi.com — a fully-fledged
IP Geolocation API platform capable of offering more than 45 data points for each processed IP address, including Time Zone data,
Currency data, Language data, Connection data, and Risk Assessment data.

ipapi.com offers a vast range of features which puts it alongside the top recommendations I have for GEO IP API
Location finding services. Let’s take a look:

Just use this link https://api.ipapi.com/api/check?access_key=YOUR_ACCESS_KEY with the language of your choice to get all the details for more details, read the documentation →

Returns:#

{
	"ip": "8.8.4.4",
	"type": "ipv4",
	"continent_code": "NA",
	"continent_name": "North America",
	"country_code": "US",
	"country_name": "United States",
	"region_code": "CA",
	"region_name": "California",
	"city": "Mountain View",
	"zip": "94043",
	"latitude": 37.419158935546875,
	"longitude": -122.07540893554688,
	"location": {
		"geoname_id": 5375480,
		"capital": "Washington D.C.",
		"languages": [
			{
				"code": "en",
				"name": "English",
				"native": "English"
			}
		],
		"country_flag": "https://assets.ipstack.com/flags/us.svg",
		"country_flag_emoji": "🇺🇸",
		"country_flag_emoji_unicode": "U+1F1FA U+1F1F8",
		"calling_code": "1",
		"is_eu": false
	},
	"time_zone": {
		"id": "America/Los_Angeles",
		"current_time": "2020-12-10T03:34:09-08:00",
		"gmt_offset": -28800,
		"code": "PST",
		"is_daylight_saving": false
	},
	"currency": {
		"code": "USD",
		"name": "US Dollar",
		"plural": "US dollars",
		"symbol": "$",
		"symbol_native": "$"
	},
	"connection": {
		"asn": 15169,
		"isp": "Google LLC"
	}
}

Pros:#

Limitations:#

IPInfo is another major player in the IP information niche. Since 2013 they have built a customer base of over 100,000 including npm, CBS, Dell, Vodafone, and serve 12 Billion IP API requests per month. The company was founded by a former Facebook engineer Ben Dowling. IPInfo boasts an incredible amount of data sets and features as listed below:

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("https://ipinfo.io/8.8.8.8/json?token=TOKEN_HERE", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "ip": "8.8.8.8",
    "hostname": "dns.google",
    "city": "Mountain View",
    "region": "California",
    "country": "US",
    "loc": "37.4056,-122.0775",
    "postal": "94043",
    "timezone": "America/Los_Angeles",
    "asn": {
        "asn": "AS15169",
        "name": "Google LLC",
        "domain": "google.com",
        "route": "8.8.8.0/24",
        "type": "business"
    },
    "company": {
        "name": "Google LLC",
        "domain": "google.com",
        "type": "business"
    }
}

Pros:#

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("ipwhois.app/json/8.8.4.4", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
	"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
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("gd.geobytes.com/GetCityDetails", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "geobytesforwarderfor": "",
    "geobytesremoteip": "39.37.167.56",
    "geobytesipaddress": "39.37.167.56",
    "geobytescertainty": "100",
    "geobytesinternet": "PK",
    "geobytescountry": "Pakistan",
    "geobytesregionlocationcode": "PKNW",
    "geobytesregion": "North-West Frontier",
    "geobytescode": "NW",
    "geobyteslocationcode": "PKNWPESH",
    "geobytesdma": "0",
    "geobytescity": "Peshawar",
    "geobytescityid": "4655",
    "geobytesfqcn": "Peshawar, NW, Pakistan",
    "geobyteslatitude": "34.016998",
    "geobyteslongitude": "71.550003",
    "geobytescapital": "Islamabad",
    "geobytestimezone": "+05:00",
    "geobytesnationalitysingular": "Pakistani",
    "geobytespopulation": "144616639",
    "geobytesnationalityplural": "Pakistanis",
    "geobytesmapreference": "Asia ",
    "geobytescurrency": "Pakistan Rupee",
    "geobytescurrencycode": "PKR",
    "geobytestitle": "Pakistan"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("//www.geoplugin.net/json.gp", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
	"geoplugin_request": "39.37.167.56",
	"geoplugin_status": 200,
	"geoplugin_delay": "2ms",
	"geoplugin_city": "Lahore",
	"geoplugin_region": "Punjab",
	"geoplugin_regionCode": "PB",
	"geoplugin_regionName": "Punjab",
	"geoplugin_areaCode": "",
	"geoplugin_dmaCode": "",
	"geoplugin_countryCode": "PK",
	"geoplugin_countryName": "Pakistan",
	"geoplugin_inEU": 0,
	"geoplugin_euVATrate": false,
	"geoplugin_continentCode": "AS",
	"geoplugin_continentName": "Asia",
	"geoplugin_latitude": "31.4909",
	"geoplugin_longitude": "74.3681",
	"geoplugin_locationAccuracyRadius": "1",
	"geoplugin_timezone": "Asia/Karachi",
	"geoplugin_currencyCode": "PKR",
	"geoplugin_currencySymbol": "₨",
	"geoplugin_currencySymbol_UTF8": "₨",
	"geoplugin_currencyConverter": 160.8406
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("ip-api.com/json", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "status": "success",
    "country": "Pakistan",
    "countryCode": "PK",
    "region": "PB",
    "regionName": "Punjab",
    "city": "Lahore",
    "zip": "54000",
    "lat": 31.4888,
    "lon": 74.3686,
    "timezone": "Asia/Karachi",
    "isp": "Pakistan Telecommuication company limited",
    "org": "Pakistan Telecommuication company limited",
    "as": "AS17557 Pakistan Telecommunication Company Limited",
    "query": "39.37.167.56"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("api.ipify.org?format=json", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
"ip": "8.8.8.8"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("api.ipinfodb.com/v3/ip-city/?key=KEY_HERE&format=json", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
	"statusCode": "OK",
	"statusMessage": "",
	"ipAddress": "119.152.180.314",
	"countryCode": "PK",
	"countryName": "Pakistan",
	"regionName": "Pakistan",
	"cityName": "Pakistan",
	"zipCode": "54000",
	"latitude": "1.28967",
	"longitude": "103.85",
	"timeZone": "+08:00"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("api.db-ip.com/addrinfo?api_key=KEY_HERE", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
	"address": "119.152.180.314",
	"country": "PK",
	"stateprov": "Central Pakistan",
	"city": "Pakistan"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("jsonip.com/", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "ip": "8.8.8.8",
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("ip.jsontest.com", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "ip": "8.8.8.8"
}

Limitations:#

var requestOptions = {
  method: 'GET',
  redirect: 'follow'
};

fetch("https://api.ipdata.co/8.8.8.8?api-key=test", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
    "ip": "8.8.8.8",
    "is_eu": false,
    "city": null,
    "region": null,
    "region_code": null,
    "country_name": "United States",
    "country_code": "US",
    "continent_name": "North America",
    "continent_code": "NA",
    "latitude": 37.751,
    "longitude": -97.822,
    "postal": null,
    "calling_code": "1",
    "flag": "https://ipdata.co/flags/us.png",
    "emoji_flag": "🇺🇸",
    "emoji_unicode": "U+1F1FA U+1F1F8",
    "asn": {
        "asn": "AS15169",
        "name": "Google LLC",
        "domain": "google.com",
        "route": "8.8.8.0/24",
        "type": "hosting"
    },
    "languages": [
        {
            "name": "English",
            "native": "English"
        }
    ],
    "currency": {
        "name": "US Dollar",
        "code": "USD",
        "symbol": "$",
        "native": "$",
        "plural": "US dollars"
    },
    "time_zone": {
        "name": "America/Chicago",
        "abbr": "CST",
        "offset": "-0600",
        "is_dst": false,
        "current_time": "2020-12-10T06:03:33.149166-06:00"
    },
    "threat": {
        "is_tor": false,
        "is_proxy": false,
        "is_anonymous": false,
        "is_known_attacker": false,
        "is_known_abuser": false,
        "is_threat": false,
        "is_bogon": false
    },
    "count": "1596"
}

Pros:#

Limitations:#

var requestOptions = {
  method: 'GET',
  headers: myHeaders,
  redirect: 'follow'
};

fetch("https://ip-geolocation.whoisxmlapi.com/api/v1?apiKey=YOUR_API_KEY", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Returns:#

{
	"ip": "110.170.64.0",
	"location": {
		"country": "TH",
		"region": "Bangkok",
		"city": "Bangkok",
		"lat": 13.7086,
		"lng": 100.4553,
		"postalCode": "10110",
		"timezone": "+07:00",
		"geonameId": 1609350
	},
	"isp": "True Internet",
	"connectionType": "broadband",
	"domains": ["110-170-64-0.static.asianet.co.th"],
	"as": {
		"asn": 7470,
		"name": "TRUE INTERNET Co.,Ltd.",
		"route": "110.170.64.0/18",
		"domain": "trueinternet.co.th",
		"type": "Cable/DSL/ISP"
	}
}

Pros:#

Limitations:#

//api.ipgeolocation.io/ipgeo?apiKey=API_KEY

Returns:#

{
	"ip": "39.45.201.56",
	"continent_code": "AS",
	"continent_name": "Asia",
	"country_code2": "PK",
	"country_code3": "PAK",
	"country_name": "Pakistan",
	"country_capital": "Islamabad",
	"state_prov": "Khyber Pakhtunkhwa",
	"district": "Peshawar",
	"city": "Peshawar",
	"zipcode": "25120",
	"latitude": "34.015",
	"longitude": "71.5805",
	"is_eu": false,
	"calling_code": "+92",
	"country_tld": ".pk",
	"languages": "ur-PK,en-PK,pa,sd,ps,brh",
	"country_flag": "https://ipgeolocation.io/static/flags/pk_64.png",
	"isp": "PTCL Triple Play Project Sialkot",
	"connection_type": "",
	"organization": "Pakistan Telecommuication company limited",
	"geoname_id": "1168197",
	"currency": {
		"name": "Rupee",
		"code": "PKR"
	},
	"time_zone": {
		"name": "Asia/Karachi",
		"offset": 5,
		"is_dst": false,
		"current_time": "2018-06-16 16:07:07.708+0500"
	}
}

Pros:#

Limitations:#

Before You Begin!#

Keep in mind that since these are all free services, your mileage may vary in terms of exceeding quota and uptime, and who knows
when/if they will be taken offline down the road. Most of these services also offer a paid tier in case you want something more
robust.

JUST A NOTE!

👨‍💻 I’m teaching thousands of devs how to become

📮 This site is super fast, isn’t it?!

It’s hosted with Kinsta on Google servers

Founder & CEO at Langbase.com · Ex VP DevRel Rapid · Google Developers Advisory Board (gDAB) founding member. 🧑‍💻 AI/ML/DevTools Angel InvestorAI/ML Advisory Board member San Francisco, DevNetwork

🎩 Award-winning Open Source Engineer & Dev Advocate 🦊 Google Developers Expert Web DevRel 🚀 NASA Mars Ingenuity Helicopter mission code contributor 🏆 8th GitHub Stars Award recipient with 3x GitHub Stars Award (Listed as GitHub's #1 JavaScript trending developer).

🌳 Node.js foundation Community Committee Outreach Lead, Member Linux Foundation, OpenAPI Business Governing Board, and DigitalOcean Navigator. 📟 Teaching thousands of developers Node.js CLI Automation (100 videos · 22 Projects) & VSCode.pro course. Over 142 Million views, 22 yrs Blogging, 56K developers learning, 200+ FOSS.

✌️ Author of various open-source dev-tools and software libraries utilized by millions of developers worldwide WordPress Core Developer 📣 TEDx Speaker with 100+ international talks.

As quoted by: Satya Nadella · CEO of Microsoft — Awais is an awesome example for developers.
🙌 Leading developers and publishing technical content for over a decade 💜 Loves his wife (Maedah) ❯ Read more about Ahmad Awais.

👋… Awais is mostly active on Twitter @MrAhmadAwais

📨

Developers Takeaway

Stay ahead in the web dev community with Ahmad's expert insights on open-source, developer relations, dev-tools, and side-hustles. Insider-email-only-content. Don't miss out - subscirbe for a dose of professional advice and a dash of humor. No spam, pinky-promise!

✨ 172,438 Developers Already Subscribed
Comments 22
  • Joseph
    Posted on

    Joseph Joseph

    Reply Author

    Thanks very much to do such a thorough survey of geolocation providers! I think it is great you took the time to detail the code and usage limits for each one. Saves me a lot of time.


  • MIke
    Posted on

    MIke MIke

    Reply Author

    can you comment on response time / latency between different services?
    thanks


    • Ahmad Awais
      Posted on

      Ahmad Awais Ahmad Awais

      Reply Author

      Yeah, I haven’t tested that far. But the code snippets would help you do that.


  • dnvenegas
    Posted on

    dnvenegas dnvenegas

    Reply Author

    Thank you for the compilation, for the information you provide and the price in the case of payment services, which gave you the best results?


  • Erkan
    Posted on

    Erkan Erkan

    Reply Author

    Thanks for the cool list. Helped me to save a lot of searching time!


  • Jen
    Posted on

    Jen Jen

    Reply Author

    Thank you for posting this list! My company is looking to replace the google API due to cost and this was a quick way to narrow down options.


  • Jonathan Kosgei
    Posted on

    Jonathan Kosgei Jonathan Kosgei

    Reply Author

    Hi Ahmad!

    I’ve been in touch via email to talk about adding ipdata to this list here. We have solid infrastructure and use latency based routing to respond to requests from one of 10 regions globally and our users also love the extra data we return i.e. calling code, currency, postal, tor node status.


  • Hung
    Posted on

    Hung Hung

    Reply Author

    Good morning Ahmad Awais,
    Could u please provide me an api_key for db-ip.com
    Thanks u so much !


  • S.Stha
    Posted on

    S.Stha S.Stha

    Reply Author

    Great article.
    FYI, http://freegeoip.net/json/?callback=? is getting deprecated by July 1, 2018.


    • Ahmad Awais
      Posted on

      Ahmad Awais Ahmad Awais

      Reply Author

      Thanks for letting me know. I switched to IPStack.


  • Ashlon Mark
    Posted on

    Ashlon Mark Ashlon Mark

    Reply Author

    thank you

    i have been add some of your code to my website!

    question: how to get ip location exact to show geolocation?

    thank you


  • Jay
    Posted on

    Jay Jay

    Reply Author

    Nice article Ahmad – Were you also able to figure out if any of these are being used commercially by companies like Target ? or Amazon ? Is there a reason why google geolocation API isn’t listed here ?


  • NoName
    Posted on

    NoName NoName

    Reply Author

    Thanks sir.


  • john smith
    Posted on

    john smith john smith

    Reply Author

    Nice


  • Will
    Posted on

    Will Will

    Reply Author

    Great list, thanks for taking the effort to post…


  • John Kolak
    Posted on

    John Kolak John Kolak

    Reply Author

    While working on a recent project for a client, I found myself in the need of a good and reasonably reliable IP Geolocation API to find out more about a user that visits your site.

    So, I did a little research for currently available APIs and came up with somewhat an exhaustive list. That is what I plan to share today.

    There were about a dozen sites that I studied.