Adding address information automatically to forms with GeoFill
One of the things I mentioned in my latest talk and the follow-up Q&A at Gumtree was that I am very interested in Geolocation and automatically detecting the user’s location to save them having to enter all the same info over and over again. Sure, location services like Fire Eagle and autofill options in browsers already do these kind of things, but they are power user toys for now.
Using Rasmus Lerdorf’s GeoIP, YQL and Yahoo Geo I’ve put together a small JavaScript wrapper that does exactly this for you:
GeoFill (also available on GitHub) allows you to use two different methods to automatically fill forms with geo information:
geofill.find(properties)does an IP lookup of the current user and tries to get the geographical data from that one.geofill.lookup(properties,postcode)tries to get the geographical data from the postcode provided in your form.
Both methods take an object which lists the form field IDs to be filled as the parameter. The data returned is city, country, postcode, latitude and longitude.
Both methods also allow you to define a callback function to handle errors or re-use the data in other ways than filling form fields.
For example to get the information connected with a post code you could simply do the following:
geofill.lookup(
{
callback:function(o){
console.log(o);
}
},'wc2h8ad');
The returned object is:
{
city:"London",
country:"United Kingdom",
latitude:"51.51384",
longitude:"-0.12857",
postcode:"WC2H 8AD"
}
Useful? In any case it made me play more with the Geo API. Don’t forget that on the 7th of July I’ll be giving a free Tech Talk on Yahoo Placemaker where this will be one of the demos (probably, knowing myself I’ll have hacked other stuff by then). You can sign up for the tech talk on upcoming.
Tags: automation, forms, geo, geoip, placemaker, usability, yql



June 8th, 2009 at 11:47 am
wowo really nice JQuery plugin for filling forms nice job.
June 8th, 2009 at 2:33 pm
would it be possible to also get the postal code?
June 8th, 2009 at 3:35 pm
@cedric not that easily. Working on it. This will be a YQL open table using Flickr, Geo and GeoIP. My head will hurt :)
June 8th, 2009 at 4:19 pm
@cedric done :-)
June 8th, 2009 at 7:22 pm
oh that is really nice, really cool for payment forms, less fields to complete is always a good thing
June 8th, 2009 at 7:42 pm
@Chris hey,
So I just ran some test, It actually returning only half of the postal code on my tests (I’m in canada),
Another cool thing would be to include the state, or province in canada.
a+
June 9th, 2009 at 3:38 pm
Hi Christian,
The script seems to be only partially working in Safari 4 final (the lookup by postcode demo works, but that’s it, I think).
Good work, though :)
Tim
June 9th, 2009 at 4:41 pm
IE7:
Line 82:
‘query.results.place.postal.content’ is null or not an object.
June 11th, 2009 at 11:04 am
Hi !
The idea is great, I love it. I tried it with chrome from Kyoto in Japan, but the result since its based on UP is quite not precise..
I wonder if this script can be more improved for reliable GeoFill use..
Well done, and thanks for the smart idea !
Amin
June 13th, 2009 at 11:32 am
Great idea… but results in Australia aren’t correct. I’m not sure how it can offer precision beyond a country.
July 7th, 2009 at 11:42 am
Well here in Europe in does work really good, the postal code was a bit of, but still very impressive!
December 7th, 2009 at 8:24 pm
I get a No definition found for Table ip.location if I use this query in code using a php curl library wrapper.
My query : select * from ip.location where ip=”92.81.173.208″
Any ideeas?
December 7th, 2009 at 8:54 pm
Got the problem fixed :
“use ‘http://www.datatables.org/iplocation/ip.location.xml’ as location
select * from location where ip=92.81.173.208 ″