0

I'm trying the code of the 1st answer here: Phonegap with Compass and GPS coordinates.

I want to adapt that don't need to input the latitude and longitude, only with 1 button saves the current position and the app start working.

I tryed making that a button call this function:

function locate(){
 if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(locationSuccess, locationError);
 }
 else {
  showError("Your browser doesn't support geolocation!");
 }
}

function locationSuccess(position) {
 $('input[id=target-lat]').val('position.coords.latitude');
 $('input[id=target-lon]').val('position.coords.longitude');
}

Any can say me what I'm making wrong?

Thanks for all.

4

1 回答 1

0
    function locate(){
    if (navigator.geolocation) {
        var location_timeout = setTimeout("geolocFail()", 10000);
        navigator.geolocation.getCurrentPosition(function(position) {
        clearTimeout(location_timeout);
        locationSuccess(position);
    }, function(error) {
        clearTimeout(location_timeout);
        geolocFail();

    });
    }else{
             showError("Your browser doesn't support geolocation!");
         }
    }

function locationSuccess(position) {
    $('input[id=target-lat]').val(position.coords.latitude);
    $('input[id=target-lon]').val(position.coords.longitude);
}
于 2013-05-13T13:59:12.390 回答