We're live-coding on Twitch! Join us!

Geo-location is the identification or estimation of the real-world geographic location of an Internet-connected computer terminal or device.

Basically, we can get location data from their IP address.

Geo-location offers a lot of advantages and increase level of customization to a website. We can:

  • Give users data in their language.
  • With knowlege of cultural differences, properly represent data.
  • Build a security layer/firewall

and many, many more features.

If you do a Google search, there are many services that offer Geo-location for a price. Or, companies like MaxMind that offer a subset of the data they’ve gathered over the years for free.

With companies like MaxMind, you have to download their database every now and then to make sure the data is up to date, manage your own servers, and all other house-keeping. That’s what IP Geolocation API will do for you.

What is IP Geolocation API and How Does it Work

IP Geolocation API, is a free to use Geo-location service.

The code is open-source which means you can deploy your version of the product and let it run all the house keeping for you. It is written in Python. So, if you need to fork and modify, you probably need to know how to code in Python.

Essential Reading: Learn React from Scratch! (2019 Edition)

When a request comes into the application,

How to Deploy a Standalone Version

Heroku is probably the best option since it’s managed.. If you already use Heroku, you can do a quick deploy by clicking this link.

Another reason to use heroku is that whenever the database gets updated, deployment is very easy.

Using the API

Currently, the API has four HTTP endpoints. **Don’t leave the slash at the end of the URL**.

GET https://api.ipgeolocationapi.com/geolocate HTTP/1.1
GET https://api.ipgeolocationapi.com/geolocate/<ip> HTTP/1.1
GET https://api.ipgeolocationapi.com/countries HTTP/1.1
GET https://api.ipgeolocationapi.com/countries/<country_code> HTTP/1.1
  • /geolocate will automatically detect the users IP address and return the location data.

  • /geolocate/<ip> requires you to supply the users IP address and returns the same data as /geolocate

  • /countries returns a list of the countries in the database and all the information they have about them.

  • /countries/<country_code> returns the information about one country.

Note: If you deployed your own version, you’ll want to replace _https://api.ipgeolocationapi.com with your own domain_

Making a request to https://api.ipgeolocationapi.com/geolocate will give you:

{
       "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":{
                "lat":55.0815,
                "lng":15.0418962
             },
             "southwest":{
                "lat":47.2701115,
                "lng":5.8663425
             }
          }
       },
       "currency_code":"EUR",
       "start_of_week":"monday"
    }

With one request, the API can infer that my Iocation is Germany, the currency, longitude and latitude and so much more.

Conclusion

If you find this project useful, be sure to give them a star on Github, make contributions and support the author however you can. Thanks!

Like this article? Follow @KayandraJT on Twitter

This content is sponsored via Syndicate Ads.