require("$UI/system/lib/cordova/cordova");
require("cordova!org.apache.cordova.geolocation");

//引用cordova以及相关插件

var options = {
timeout : 10000
};
function onSuccess(position) {
Longitude=position.coords.longitude;
Dimension=position.coords.latitude;
if (this.watchID) {
navigator.geolocation.clearWatch(this.watchID);
this.watchID = null;
}
}
function onError(error) {  

alert('失败编码: ' + error.code + '\n' +
'失败信息: ' + error.message + '\n');

}

//code:一个在下面常量列表中定义的错误代码。
//message:说明错误细节的错误信息。
//PositionError.PERMISSION_DENIED:权限被拒绝
//PositionError.POSITION_UNAVAILABLE:位置不可用
//PositionError.TIMEOUT:超时

navigator.geolocation.watchPosition(onSuccess, onError, options);

 

 

注意:当手机断开网络,无法获取到GPS的时候:

1.将手机的安全中心打开,给当前APP设置使用GPS权限

2.设置GPS,将定位模式改为:仅限设备模式(使用GPS确定您的位置)

相关文章:

  • 2021-12-15
  • 2021-08-25
  • 2021-10-11
  • 2021-11-28
  • 2021-06-24
  • 2021-12-07
  • 2021-08-10
  • 2021-11-19
猜你喜欢
  • 2021-10-05
  • 2022-01-01
  • 2022-12-23
  • 2021-10-12
  • 2021-12-02
  • 2022-12-23
  • 2021-08-22
相关资源
相似解决方案