本帖最后由 cbb66 于 2018-5-29 17:00 编辑
打包成app后,定位失败后会进入手机的定位服务设置,不会提示定位失败。Model.prototype.setLocation = function() { if(typeof device === "undefined") return; var _this = this; navigator.geolocation.getCurrentPosition(function(position){ var lat = position.coords.latitude;//获取到纬度 var lon = position.coords.longitude;//获取到经度 _this.lat = lat; _this.lon = lon; var url = 'https://api.map.baidu.com/geocoder/v2/?ak=XwQGPoOFhERnqBlGHtp7QQ4UgjAkoqc6&callback=renderReverse&location=' + lat + ',' + lon + '&output=json&pois=1'; $.ajax({ url : url, dataType : 'jsonp', processData : false, type : 'get', success : function(data) { _this.isLocationFlag = true; if(!_this.getElementByXid('locating')){ return; } _this.getElementByXid('locating').style.display = "none"; _this.getElementByXid('signName').style.display = "block"; _this.getElementByXid('time').style.display = "block"; _this.clockingInAdddress = data.result.pois[0].name; $(_this.getElementByXid('address')).html("考勤地点:"+data.result.pois[0].name); }, error : function(XMLHttpRequest, textStatus, errorThrown) { if(!_this.getElementByXid('locating')){ return; } $(_this.getElementByXid('locating')).html('重新定位'); } });
},function(err){ console.error(err); if (device && device.platform == "Android") { if(cordova.plugins.settings && typeof cordova.plugins.settings.openSetting != "undefined"){ cordova.plugins.settings.openSetting("location_source", function(){ }, function(){ main_this.comp('msgDialog').show({ type: 'OK', message: '打开定位服务失败!' }); }); } } else { //iOS无需添加参数 cordova.plugins.settings.open(function(){ console.log("opened settings"); }, function(){ main_this.comp('msgDialog').show({ type: 'OK', message: '打开定位服务失败!' }); }); } },{ timeout: 60000},"bd09ll"); //再次调用函数关闭GPS //navigator.geolocation.getCurrentPosition(function(){},function(){},null,"bd09ll"); };
|