GeoIP tracking with Google APIs
If you want to track visitors to know where they are coming from, the normal un*x’ish way of doing this is to grab maxmind’s geoiplookup (or apt-get/rpmfind) and then run it against the web server logs. That’s so not Web 2.0. *ugh*
Google’s hosted JavaScript API’s makes this so much easier. All you have to do is include:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
in your web page and voila’, you have the client location. How? If you directly navigate to the jsapi, you’ll see the following:
google.loader.ClientLocation
which pretty much gives you all you need to locate the user. Do a jQuery post to your web server and you know exactly where the user is coming from. Here’s a better example. The map below uses Google’s Map API to show you where you are viewing this blog from.
Posted in JavaScript | Permalink | Trackback
April 6th, 2009 at 12:34 am
Sounds very interesting. Unfortunately it always gives null to me, even though I’m not trying to do anything to hide myself :-)
Tried it from two different IP addresses (from two different provides) in Romania.
April 6th, 2009 at 6:36 am
Can you try navigating directly to the jsapi URL and see if you have the google.loader.ClientLocation line?
April 6th, 2009 at 7:21 am
I did that and it said “google.loader.ClientLocation = null” from both of the IPs.
Update: I’ve tried from a third IP and it also has null. Maybe it is limited to certain countries / ISPs.
April 6th, 2009 at 7:49 am
Apparently it doesn’t always work. :-(
http://code.google.com/apis/ajax/documentation/#ClientLocation