WebX5手机GPS定位,无需开启网络

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确定您的位置)

posted @ 2015-08-03 17:26  一切为了生存  阅读(656)  评论(0编辑  收藏  举报