AppEngine Location Detection Update : X-AppEngine-Country and more

Google App Engine has announced version 1.6.5 of its App Engine SDK. I was pleasantly surprised to find an excellent feature that was hidden away in the Release Notes. Here is the nugget:

I had covered earlier on X-AppEngine-country and the fact that it worked quite well. And I had suggested just offhand that Google should probably take this one still further and provide other fine grained information too like city. It looks like they have gone further than that and include region, city and latitude / longitude.

In addition to the X-AppEngine-Country in the request header, it has now introduced the following additional location based headers with each request:

  • X-AppEngine-Region
  • X-AppEngine-City
  • X-AppEngine-CityLatLong
The availability of this information is surely going to be useful to a lot of applications that earlier had to resort to additional network calls to get this information from the IP Address.
To test out, I wrote a simple Google App Engine Java project which has a single page (index.jsp) that simply sniffs the value of these header and prints it out and shows a map of where you are visiting from.
Here is the snippet of code that prints out the different header values based where you are accessing the page:
<h2>Hello My Friend. Your co-ordinates are: </h2>
<h3> Country : <%=request.getHeader("X-AppEngine-Country") %></h3>
<h3> Region : <%=request.getHeader("X-AppEngine-Region") %></h3>
<h3> City : <%=request.getHeader("X-AppEngine-City") %></h3>
<h3> Latitude,Longitude : <%=request.getHeader("X-AppEngine-CityLatLong") %></h3>

Since I live in India, it does a good job and prints out the following (as shown in the screenshot below):

You can try it too.

Do you envision using this in your application? What have you been using so far to get similar functionality?

Source Code on GitHub.

Read more Episodes on App Engine Services

 

About these ads

About rominirani

Google Developer Expert Cloud 2014. Harnessing the power of software by learning, teaching and developing simple solutions. I love learning about new technologies and teaching it to others.
This entry was posted in Google App Engine. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s