Apache Cordova地理位置不提供数据



我正在使用Apache Cordova将设备的LAT和长坐标传递到Parse数据库。但是,坐标返回空白,没有出现错误警报。JSFIDDLE不显示语法错误。

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 }

看来您使这是反转的:

更改:

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

to:

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

我也有同样的问题。我通过明确安装插件来修复它:cordova plugin add cordova-plugin-geolocation

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

希望这对您有帮助!:)

最新更新