Sunday, November 24, 2013

I'll go build my own JSONIP! Or tiny web service for user geo location

Maybe it will be the most tiny web service I have ever made but not less important than others.


I often create experimental webapps and need to know approximately the position of the user even if Geolocation.getCurrentPosition() doesn't work.

Why brand new feature of html5 Geolocation.getCurrentPosition() is not enough? When my webapp starts I want to show to the user most relevant information. But at the moment user doesn't know anything about my webapp so with high probability he will say - No to Geolocation.getCurrentPosition(). So why don't we do the 1st step and show the most relevant information without asking for Geolocation.getCurrentPosition()? And only after the user will really want more relevant information and will be ready for a request of Geolocation.getCurrentPosition() - then we will use it.

So this is my point.

What we have

    returns: {"ip":"*.*.*.*","about":"/about","Pro!":""} So it returns position only for pro version

    returns: {"ip": "*.*.*.*", "address":""}", "address":"*.*.*.*"}

It returned position earlier but now it returns only IP. And even then it is overquored sometimes.

So why don't we create our own web services?

Lets try

I'll go build my own JSONIP, with blackjack and hookers. Wait a minute ... - to be more correct it will be with ip and geo location! :)

I decide to create my own jsonip web service on the same GAE platform.

So here are the questions that I have got on my way to do it:

get a user ip



get user Geo location

We are very happy with GAE - because it already provides the Geo location information inside the request: docs


But we can get more - Country, Region, City. It's really cool!

response json

It is the easiest question but anyway docs

test local and global

When you run your web service locally you won't get any IP and Geo information - So test it on GAE.



Emulate jsonp article


And support brand new CORS

self.response.headers.add_header('Access-Control-Allow-Origin', '*')


If you are too lazy to create your own Geo location web services on GAE and want to use the one I created, just ask. Otherwise if you are going to do it without my consent I'll just lock Access-Control-Allow-Origin to support only my domains.


All sources are there

No comments :

Post a Comment