Javascript Apache Cordova地理位置不提供数据
我使用apachecordova获取设备的lat和long坐标,并将其传递给解析数据库。但是,坐标将返回空白,并且不会出现错误警报。JSFIDLE没有显示语法错误Javascript Apache Cordova地理位置不提供数据,javascript,apache,cordova,geolocation,Javascript,Apache,Cordova,Geolocation,我使用apachecordova获取设备的lat和long坐标,并将其传递给解析数据库。但是,坐标将返回空白,并且不会出现错误警报。JSFIDLE没有显示语法错误 document.addEventListener("deviceready", onDeviceReady, false); var lat1=""; var long1=""; // Cordova is ready function onDeviceReady() { navigator.geolocation.get
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;
致:
我也有同样的问题。我通过显式安装插件修复了它:cordova plugin add cordova plugin geolocation 但是,我使用的是$cordovaGeolocation.getCurrentPosition,而不是navigator.geolocation.getCurrentPosition
希望这对你有帮助!: 多谢各位。我更正了,但它仍然没有传递任何数据。在onDeviceReady函数中添加了一个警报命令,但没有看到警报后,我得出结论,该错误与设备未就绪有关。不确定该怎么办。在onDeviceReady函数中添加了一个警报命令,但没有看到警报后,我得出结论,该错误与设备未准备就绪有关。不知道该怎么办。
long1 = position.coords.longitude;
lat1 = position.coords.latitude;