本文介绍了Apache的科尔多瓦GeoLocation中未提供数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Apache科尔多瓦得到一个设备的纬度和经度坐标传授给解析数据库。然而,坐标返回空白,并没有出现错误警报。的jsfiddle显示没有语法错误。

  document.addEventListener(deviceready,onDeviceReady,FALSE);
变种LAT1 =;变种long1 =;//科尔多瓦准备就绪
功能onDeviceReady(){
    navigator.geolocation.getCurrentPosition(的onSuccess,onError的,期权);
 警报(设备准备好了!);
}//的onSuccess地理位置
功能的onSuccess(位置){
    long1 = position.coords.longitude;
    LAT1 = position.coords.latitude;
}// onerror的回调收到PositionError对象
功能onError的(错误){
    警报(无法获取位置);
}功能选项(){enableHighAccuracy:真正}


解决方案

我有同样的问题。我通过明确安装插件固定它:科尔多瓦插件添加科尔多瓦 - 插件,地理位置

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

希望这可以帮助您! :)

I'm using Apache Cordova to get the lat and long coordinates of a device to pass on to a parse database. However, the coordinates are returning blank and no error alert appears. JSFiddle shows no syntax errors.

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 }
解决方案

I had the same problem. I fixed it by explicitly installing the plugin: cordova plugin add cordova-plugin-geolocation

However, I'm using $cordovaGeolocation.getCurrentPosition, not navigator.geolocation.getCurrentPosition.

Hope this help you! :)

这篇关于Apache的科尔多瓦GeoLocation中未提供数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:39