繁体   English   中英

Apache Cordova GeoLocation不提供数据

[英]Apache Cordova GeoLocation not providing data

我正在使用Apache Cordova获取设备的经纬度坐标,然后将其传递给解析数据库。 但是,坐标返回空白,并且不会出现错误警报。 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;

至:

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

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

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

希望这对您有所帮助! :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM