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 - automatically filling form data with geo information by  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: , , , , , ,

13 Responses to “Adding address information automatically to forms with GeoFill”

  1. webmasterdubai Says:

    wowo really nice JQuery plugin for filling forms nice job.

  2. Cedric Dugas Says:

    would it be possible to also get the postal code?

  3. Chris Says:

    @cedric not that easily. Working on it. This will be a YQL open table using Flickr, Geo and GeoIP. My head will hurt :)

  4. Chris Says:

    @cedric done :-)

  5. Cedric Dugas Says:

    oh that is really nice, really cool for payment forms, less fields to complete is always a good thing

  6. Cedric Dugas Says:

    @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+

  7. Tim Beadle Says:

    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

  8. Marty Says:

    IE7:

    Line 82:
    ‘query.results.place.postal.content’ is null or not an object.

  9. Amin Says:

    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

  10. Edward Says:

    Great idea… but results in Australia aren’t correct. I’m not sure how it can offer precision beyond a country.

  11. David Says:

    Well here in Europe in does work really good, the postal code was a bit of, but still very impressive!

  12. Gafitescu Daniel Says:

    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?

  13. Gafitescu Daniel Says:

    Got the problem fixed :

    “use ‘http://www.datatables.org/iplocation/ip.location.xml’ as location
    select * from location where ip=92.81.173.208 ″

Leave a Reply

Wait till I come! is the blog of Christian Heilmann , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).