// will put link in div with id 'geo_location'
// assumes that there's a textbox called 'where' which will get the location
 function handler(location) {
        var where = document.getElementById("where");
        var lat = 0;
        var lng = 0;
        if (location.coords != undefined){
            lat = location.coords.latitude;
            lng = location.coords.longitude;
        }
        else if (location.latitude != undefined){
            lat = location.latitude;
            lng = location.longitude;
        }
        jQuery.getJSON('/geop.p',{a:'getLocationForLatLong',lt:lat,ln:lng}, function(data) {
            if (data.length > 0){
                if (where != undefined){
                    where.value = data[0].location;
                }
                jQuery('.location').each(function() { this.value=data[0].location;});
            }


        }  );

        /** Use class="gpslocation" will do actual coordinates **/
        if (lat > 0 || lng > 0){
            jQuery('.gpslocation').each(function() { this.value=lat + ',' + lng; });
        }
        return false;
    }

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"));
        navigator.geolocation.getCurrentPosition(handler);
    }
    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"));
          google.gears.factory.create('beta.geolocation').getCurrentPosition(handler);
      }
    });


