// will put link in div with id 'geo_location'
// assumes that there's a textbox called 'where' which will get the location
jQuery(document).ready(function() {
    var href = undefined;
      if(navigator.geolocation !== undefined) {
    /* iPhone OS3 or any phone supporting w3c gelocation */
        var link = document.createElement("a");
        link.setAttribute("href","javascript:navigator.geolocation.getCurrentPosition(handler);");
        link.innerHTML = 'Update (GPS)';
        document.getElementById('geo_location').appendChild(link);
        document.getElementById('geo_location').appendChild(document.createElement("br"));
    }
    else if (window.google && google.gears) {
        var link = document.createElement("a");
        link.setAttribute("href","javascript:google.gears.factory.create('beta.geolocation').getCurrentPosition(handler);");
        link.innerHTML = 'Update (GPS)';
        document.getElementById('geo_location').appendChild(link);
        document.getElementById('geo_location').appendChild(document.createElement("br"));
      }
    });

    function handler(location) {
        var where = document.getElementById("where");
        var lat = 0;
        var long = 0;
        if (location.coords != undefined){
            lat = location.coords.latitude;
            long = location.coords.longitude;
        }
        else if (location.latitude != undefined){
            lat = location.latitude;
            long = location.longitude;
        }
        jQuery.getJSON('/geop.p',{a:'getLocationForLatLong',lt:lat,ln:long}, function(data) {
            if (data.length > 0){
                where.value = data[0].location;
            }
        }  );

        return false;
    }