2013-05-13 49 views
0

我正在嘗試第一個答案的代碼在這裏:Phonegap with Compass and GPS coordinates地理定位,用1個按鈕獲取長和緯度

我想適應不需要輸入緯度和經度,只有1按鈕保存當前位置和應用程序開始工作。

我tryed做一個按鈕調用這個函數:

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

任何可以說我什麼,我作出錯誤的?

謝謝大家。

回答

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); 
} 
+0

編輯答案。移除locationSuccess函數中的單引號 – vasanth 2013-05-13 18:22:12

相關問題