Monday, June 8th, 2009

GeoFill – find users by IP or lookup and prefill forms for them

Category: Library, Yahoo!

One thing that annoys me is that in the days of geolocation and location recognition I still have to enter my country and city in forms over and over again. This is especially annoying when you like in the UK which could be anywhere in these wonderful large dropdowns (UK, England, Great Britain, United Kingdom, Blighty…).

There are many geo lookup tools and a lot of (at least UK) web sites started doing post code lookup tools. This is cool, but as annoying when I spent another reload of a full large form for a postcode lookup that went wrong. With the UK being quite a mess when it comes to post codes this is not uncommon.

Now, to work around these issues I’ve put together a small JavaScript wrapper library called GeoFill (also available on GitHub). This one makes it easy to provide a “is this your location” functionality in JavaScript:

GeoFill - automatically filling form data with geo information by  you.

GeoFill has 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 can either automatically fill a form when you provide them with an object telling it which info should go into the form with a given ID, but also have a callback property that allows you to use the data immediately


  1. geofill.lookup(
  2.   {
  3.     callback:function(o){
  4.       console.log(o);
  5.   }
  6. },'wc2h8ad');

The returned object is:


  1. {
  2.   city:"London",
  3.   country:"United Kingdom",
  4.   latitude:"51.51384",
  5.   longitude:"-0.12857",
  6.   postcode:"WC2H 8AD"
  7. }

The find method uses the GeoIP lookup:


  1. geofill.find({
  2.   callback:function(o){
  3.     console.log(o);
  4.   }
  5. });

And returns (in my case):


  1. {
  2.   city:"London",
  3.   country:"United Kingdom",
  4.   latitude:"51.5",
  5.   longitude:"-0.11670000106096",
  6.   postcode:"WC2H 8AD"
  7. }

Posted by Chris Heilmann at 5:03 am
1 Comment

3.5 rating from 20 votes

1 Comment »

Comments feed TrackBack URI

Might come in handy.

One small note about the postcode lookup. It might be better to also ask for the country to search in as optional agrument. If i search for my postcode it says i’m from New Zealand.. Thats only 11 465 miles
from here ;)

Comment by V1 — June 8, 2009

Leave a comment

You must be logged in to post a comment.