Free IP-based GeoLocation with Google Cloud Functions


GeoLocation services — prices and limits

IPStack (was FreeGEOIP.net)

Free requests: 10 000 per month First tier: 9.99 USD for 50 000 requests per month

geoipify.whoisxmlapi.com

Free requests: 1000 per month First tier: 27.00 USD for 100 000 queries per month

db-ip.com

First tier (Basic API): ~18.70 USD for 10,000–50,000 requests per day Has three different versions of the API: Basic, Core, and Extended. It gets more expensive with the level of details needed.


GeoLocation with Google Cloud Functions — prices and limits

Free requests: First 2 million invocations per Month (combined for all functions) Beyond 2 million: 0.40 USD per million invocations Extra cost: Compute Time

Get the Google Cloud Function up and running

First of all, you need a Google Cloud account with a billing account setup. If you don’t have one, click here to create one. You will get 300 USD free credit to spend within 12 months.

Click the “Enable API” button the enable Cloud Functions API
Click the “Create function” button to create a new function
Give the function a name. “geolocation” for example.
Basic code used for IP-based GeoLocation
Real IP address omitted

Extend the function

The function is working, but let’s say you need more features, like receiving data about the proxy. That’s possible through the “X-Forwarded-For” header. For more details about each header please read: https://cloud.google.com/appengine/docs/flexible/nodejs/reference/request-headers

Real IP address omitted

Usage and advantages

Our Google Cloud Function will work great with apps written in Vue.js, React, Angular and other frameworks. It is decoupled from any back-end, and its up-time will be exceptional. After all, it’s serverless.

Contribute

We published a public repository at https://github.com/ministryofprogramming/gcf-geolocation. The code described in this article is just the starting point. Feel free to clone the repository, implement new features and make a pull request so that others can benefit from your improvements.

Ministry of Programming

Having built technology businesses from the first line of code to over 250 million USD market caps, Ministry of Programming is the future of technical co-founding. We write about Software Architecture, Technology Trends and stories from our trenches.

Eldar Ćejvanović

Written by

Software Developer @ Ministry of Programming.

Ministry of Programming

Having built technology businesses from the first line of code to over 250 million USD market caps, Ministry of Programming is the future of technical co-founding. We write about Software Architecture, Technology Trends and stories from our trenches.