Tuesday, June 29, 2010

Filling Address Fields using HTML5 Geolocation and jQuery

I saw an interesting tweet by Remy Sharp (@rem) the other day that sparked my interest.


So, I proceeded to research the Geolocation API and look up various web services that allowed me to utilize JSONP requests from jQuery.

Here is some pseudocode to describe what I came up with…

if (Your browser supports the GeoLocation API) { 
  if (Geolocation data contains address) { 
    Use address to populate form (Firefox) 
  } else { 
    Use Long/Lat to get address from web service & populate form (Chrome) 
} else {
  Use IP address to get address from web service & populate form (IE)



Note: You may notice depending on the browser not all of the fields are being filled out. This is because of the web services that I am utilizing are lacking one or more fields or vary depending on your location. If I find a better web service then I’ll update the script.

No comments:

Post a Comment