2014-01-25 36 views
1

我使用Apache Cordova將設備的經緯度座標傳遞給解析數據庫。但是,座標將返回空白,並且不會顯示錯誤警報。 JSFiddle不顯示語法錯誤。Apache Cordova GeoLocation不提供數據

document.addEventListener("deviceready", onDeviceReady, false); 
var lat1=""; var long1=""; 

// Cordova is ready 
function onDeviceReady() { 
    navigator.geolocation.getCurrentPosition(onSuccess, onError, options); 
alert("Device is ready!"); 
} 

// onSuccess Geolocation 
function onSuccess(position) { 
    long1=position.coords.longitude; 
    lat1=position.coords.latitude; 
} 

// onError Callback receives a PositionError object 
function onError(error) { 
    alert("unable to get location"); 
} 

function options(){ enableHighAccuracy: true } 
+0

在'onDeviceReady'函數中添加'alert'命令並且沒有看到警報之後,我得出結論,錯誤與設備未「就緒」有關。不知道該怎麼辦。 – user2883848

回答

0

看來你這倒:

變化:

position.coords.longitude=long1; 
position.coords.latitude=lat1; 

要:

long1 = position.coords.longitude; 
lat1 = position.coords.latitude; 
+0

謝謝。我糾正了這一點,但它仍然沒有傳遞任何數據。在'onDeviceReady'函數中添加'alert'命令並且沒有看到警報之後,我得出結論,錯誤與設備未「準備就緒」有關。不知道該怎麼辦。 – user2883848

0

我有同樣的問題。我通過明確安裝插件來修復它:cordova plugin add cordova-plugin-geolocation

但是,我使用的是$cordovaGeolocation.getCurrentPosition而不是navigator.geolocation.getCurrentPosition

希望這對你有所幫助! :)