地理定位,长按和1按钮

时间:2013-05-13 13:43:55

标签: android html5 cordova jquery-mobile

我正在尝试第一个答案的代码:Phonegap with Compass and GPS coordinates

我想适应不需要输入纬度和经度,只需1个按钮就可以保存当前位置并且应用程序开始工作。

我尝试按下这个功能按钮:

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');
}

任何人都可以说我做错了吗?

谢谢大家。

1 个答案:

答案 0 :(得分: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);
}