Wednesday, September 9, 2015

How to obtain user geolocation with Google App Engine

Sometimes it is good to provide a better user experience by obtaining geolocation of a user. In Google App Engine, we can use the information in python
os
package to achieve this:

Get the current city of a user:

Get the current country of a user (Will return a ISO 3166-1 alpha-2 country code):

Note: If App Engine fails to supply a city name or country code, the output will be the second argument supplied to the
os.environ.get()
function call.

Update 13 Oct 2015: Added a Demo link

Update 7 Nov 2015: Added complete source code.

1 comment:

Note: Only a member of this blog may post a comment.