Location tracking with AppEngine

63 views
Skip to first unread message

theillustratedlife

unread,
Jan 30, 2009, 2:23:02 PM1/30/09
to Google App Engine
I'm interested in adding geolocation to my app. Specifically, I'd
like to find the city/metro area a user is in to serve localized
results.

I've done some brief research, and this pattern is emerging:

1) Serve a location-untargeted html file.

2) Include some JavaScript in that file that searches for a location
API (e.g. Gears, Google AJAX APIs, Mozilla Geode), parses the city the
user is in, and sends it back to a handler on my app.

3) My app would then find the relevant data and send it back for the
JavaScript to inject into the page.


Ideally, I'd have a rough idea of the user's location the first time
(IP targeting). Any tips?

Marzia Niccolai

unread,
Jan 30, 2009, 2:34:48 PM1/30/09
to google-a...@googlegroups.com
Hi,

I've been working a sample that does something similar to this (note
to self: publish soon :). In the meantime, I can definitely suggest
using Google Gear's geolocator:
http://code.google.com/apis/gears/api_geolocation.html#geolocation
and the Google Maps geolocation library:
http://code.google.com/apis/maps/documentation/

I didn't have any experience with Maps/Geo before working on my
sample, (and know only basic javascript) but I found it was very quick
to get something workable together. To find out where your user is,
the Gears code needed is (more or less):

<script type="text/javascript">
var geo = google.gears.factory.create('beta.geolocation');
var geocoder = null;
var lat = null;
var lon = null;
var map = null;

function loadresources(){
if (!window.google || !google.gears) {
location.href = "http://gears.google.com/?action=install&message=" +

"To%20use%20Mutiny%27s%20auto-location%20feature%2C%20you%27ll%20need%20to%20install%20gears"
+
"&return=http%3A%2F%2F24hrsinsf.appspot.com%2F";
}

geo.watchPosition(updatePosition, handleError, {enableHighAccuracy: true});

return true;

}

function updatePosition(position) {
if(lat == null){
lat = position.latitude;
lon = position.longitude;
var current_location = new GLatLng(lat, lon);
geocoder = new GClientGeocoder();
map = new GMap2(document.getElementById("map_canvas"));
geocoder.getLocations(current_location, showAddress)
old_overlay = current_location
map.setCenter(current_location, 13);
var marker = new GMarker(current_location);
map.addOverlay(marker);

}
}
</script>
<body onload="loadresources()">

Here, using the Gears option enableHighAccuracy will not call
updatePosition until a very accurate user position can be found.

Perhaps other people on the group can suggest other methods that have
helped them!

-Marzia

theillustratedlife

unread,
Jan 30, 2009, 6:10:52 PM1/30/09
to Google App Engine
Thanks Marzia. Your site has incredible accuracy (it got to the
nearest street-corner when I'm at home on my desktop).

So it looks like the solution is still to use JavaScript + Gears. Any
tips for guessing their location if they don't have Gears installed?
(Keep in mind, I'm looking at the neighborhood/metro level).

Barry Hunter

unread,
Jan 30, 2009, 6:33:13 PM1/30/09
to google-a...@googlegroups.com
See
http://google-code-updates.blogspot.com/2008/08/two-new-ways-to-location-enable-your.html
for another. (the second one mentioned is Gears ;)

2009/1/30 theillustratedlife <toons...@nvbell.net>:
--
Barry

- www.nearby.org.uk - www.geograph.org.uk -

N. Rosencrantz

unread,
Feb 1, 2009, 5:44:09 AM2/1/09
to Google App Engine
> tips for guessing theirlocationif they don't have Gears installed?
> (Keep in mind, I'm looking at the neighborhood/metro level).

geoip is one established way. display client location works with geoip
(with a gmap (such as classifiedsmarket.appspot.com))

<br>Country Code:
<script language="JavaScript">document.write(geoip_country_code());</
script>
<br>Country Name:
<script language="JavaScript">document.write(geoip_country_name());</
script>
<br>City:
<script language="JavaScript">document.write(geoip_city());</script>
<br>Region:
<script language="JavaScript">document.write(geoip_region());</
script>
<br>Latitude:
<script language="JavaScript">document.write(geoip_latitude());</
script>
<br>Longitude:
<script language="JavaScript">document.write(geoip_longitude());</
script>
and reverse geocodes:
var reversegeocoder = new GReverseGeocoder(map);
GEvent.addListener(reversegeocoder, "load",
function(placemark) {
document.getElementById("message").innerHTML =
placemark.address
}
);

regards

mb

unread,
Feb 1, 2009, 8:13:09 AM2/1/09
to Google App Engine
There are instances when doing it using JavaScript isn't nearly as
good as doing it on the server. To do it on the server, you can
import a database like MaxMind, but it's a bit of a pain.

Or you can vote for the issue at http://code.google.com/p/googleappengine/issues/detail?id=803
and hope :)

nickmilon

unread,
Feb 2, 2009, 6:43:42 PM2/2/09
to Google App Engine
Sorry haven't read this entry sooner.
As a matter of fact I developed a geolocation through ip service last
May as a test for then just released App Engine.
I was interested to test Big table's performance at the time.
So I created a Big Table model and loaded it with all ip blocks
collected by automatically fetching related entries from various
RIR's ARIN, APNIC etc.
It is around 90.000 Big Table entries, and I developed a small
procedure for uploading - updating all this to BT which proved very
fast too.

With proper indexing it only needs one equality filter and it is quite
fast although more optimization can be applied.
You can try it here :


http://milon.appspot.com/stravon/db/cc/83.212.217.149
(First call can be slow coz this App is sleeping.)

last part of URL is any IP and returns the Country code of that IP
(it works only with ipV4), although I have an other table with IPV6

Of course more development is needed for this to become a really
useful service, but I was really impressed by Big table's
performance.

Any body interested can contact me.
Take care
Nick

nick...@gmail.com

nickmilon

unread,
Feb 2, 2009, 6:44:00 PM2/2/09
to Google App Engine

nickmilon

unread,
Feb 2, 2009, 6:47:10 PM2/2/09
to Google App Engine
Reply all
Reply to author
Forward
0 new messages