|
|
@@ -57,104 +57,104 @@
|
|
|
// #endif
|
|
|
},
|
|
|
onShow: function(e) {
|
|
|
- // #ifdef APP-PLUS
|
|
|
- this.getLocation();
|
|
|
- // #endif
|
|
|
+ // // #ifdef APP-PLUS
|
|
|
+ // this.getLocation();
|
|
|
+ // // #endif
|
|
|
},
|
|
|
onHide: function() {},
|
|
|
methods: {
|
|
|
- getLocation() {
|
|
|
- uni.getLocation({
|
|
|
- type: 'gcj02', // 根据需要选择坐标类型
|
|
|
- geocode: true,
|
|
|
- success: (res) => {
|
|
|
- this.saveLocation(res);
|
|
|
- if (this.locationInterval) {
|
|
|
- clearInterval(this.locationInterval);
|
|
|
- }
|
|
|
- // 设置每小时重新获取坐标
|
|
|
- this.locationInterval = setInterval(() => {
|
|
|
- this.updateLocation();
|
|
|
- }, 3600000); // 3600000毫秒 = 1小时
|
|
|
+ // getLocation() {
|
|
|
+ // uni.getLocation({
|
|
|
+ // type: 'gcj02', // 根据需要选择坐标类型
|
|
|
+ // geocode: true,
|
|
|
+ // success: (res) => {
|
|
|
+ // this.saveLocation(res);
|
|
|
+ // if (this.locationInterval) {
|
|
|
+ // clearInterval(this.locationInterval);
|
|
|
+ // }
|
|
|
+ // // 设置每小时重新获取坐标
|
|
|
+ // this.locationInterval = setInterval(() => {
|
|
|
+ // this.updateLocation();
|
|
|
+ // }, 3600000); // 3600000毫秒 = 1小时
|
|
|
|
|
|
- // 重置错误通知状态
|
|
|
- this.errorNotified = false;
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- if (!this.errorNotified) {
|
|
|
- this.handleLocationError(err);
|
|
|
- this.errorNotified = true;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- updateLocation() {
|
|
|
- uni.getLocation({
|
|
|
- type: 'gcj02',
|
|
|
- geocode: true,
|
|
|
- success: (res) => {
|
|
|
- this.saveLocation(res);
|
|
|
- },
|
|
|
- fail: (err) => {
|
|
|
- if (!this.errorNotified) {
|
|
|
- this.handleLocationError(err);
|
|
|
- this.errorNotified = true;
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- saveLocation(res) {
|
|
|
- uni.setStorage({
|
|
|
- key: 'location',
|
|
|
- data: {
|
|
|
- latitude: res.latitude,
|
|
|
- longitude: res.longitude,
|
|
|
- province: res.address.province,
|
|
|
- city: res.address.city,
|
|
|
- district: res.address.district,
|
|
|
- street: res.address.street,
|
|
|
- streetNum: res.address.streetNum,
|
|
|
- poiName: res.address.poiName,
|
|
|
- cityCode: res.address.cityCode
|
|
|
- },
|
|
|
- success: () => {}
|
|
|
- });
|
|
|
- },
|
|
|
- handleLocationError(err) {
|
|
|
- uni.showModal({
|
|
|
- title: '获取权限',
|
|
|
- content: '晋掌柜有道路救援服务,需要获取位置信息',
|
|
|
- success: ({
|
|
|
- confirm,
|
|
|
- cancel
|
|
|
- }) => {
|
|
|
- setTimeout(() => {
|
|
|
- if (confirm) {
|
|
|
- this.openLocationSettings();
|
|
|
- }
|
|
|
- if (cancel) {
|
|
|
- this.exitApp();
|
|
|
- }
|
|
|
- }, 0);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- openLocationSettings() {
|
|
|
- if (uni.getSystemInfoSync().platform == 'android') {
|
|
|
- var Intent = plus.android.importClass('android.content.Intent');
|
|
|
- var Settings = plus.android.importClass('android.provider.Settings');
|
|
|
- var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
- var main = plus.android.runtimeMainActivity();
|
|
|
- main.startActivity(intent);
|
|
|
- }
|
|
|
- },
|
|
|
- exitApp() {
|
|
|
- if (plus.os.name === "Android") {
|
|
|
- plus.runtime.quit();
|
|
|
- } else {
|
|
|
- plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
|
|
|
- }
|
|
|
- },
|
|
|
+ // // 重置错误通知状态
|
|
|
+ // this.errorNotified = false;
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // if (!this.errorNotified) {
|
|
|
+ // this.handleLocationError(err);
|
|
|
+ // this.errorNotified = true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // updateLocation() {
|
|
|
+ // uni.getLocation({
|
|
|
+ // type: 'gcj02',
|
|
|
+ // geocode: true,
|
|
|
+ // success: (res) => {
|
|
|
+ // this.saveLocation(res);
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // if (!this.errorNotified) {
|
|
|
+ // this.handleLocationError(err);
|
|
|
+ // this.errorNotified = true;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // saveLocation(res) {
|
|
|
+ // uni.setStorage({
|
|
|
+ // key: 'location',
|
|
|
+ // data: {
|
|
|
+ // latitude: res.latitude,
|
|
|
+ // longitude: res.longitude,
|
|
|
+ // province: res.address.province,
|
|
|
+ // city: res.address.city,
|
|
|
+ // district: res.address.district,
|
|
|
+ // street: res.address.street,
|
|
|
+ // streetNum: res.address.streetNum,
|
|
|
+ // poiName: res.address.poiName,
|
|
|
+ // cityCode: res.address.cityCode
|
|
|
+ // },
|
|
|
+ // success: () => {}
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // handleLocationError(err) {
|
|
|
+ // uni.showModal({
|
|
|
+ // title: '获取权限',
|
|
|
+ // content: '晋掌柜有道路救援服务,需要获取位置信息',
|
|
|
+ // success: ({
|
|
|
+ // confirm,
|
|
|
+ // cancel
|
|
|
+ // }) => {
|
|
|
+ // setTimeout(() => {
|
|
|
+ // if (confirm) {
|
|
|
+ // this.openLocationSettings();
|
|
|
+ // }
|
|
|
+ // if (cancel) {
|
|
|
+ // this.exitApp();
|
|
|
+ // }
|
|
|
+ // }, 0);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // openLocationSettings() {
|
|
|
+ // if (uni.getSystemInfoSync().platform == 'android') {
|
|
|
+ // var Intent = plus.android.importClass('android.content.Intent');
|
|
|
+ // var Settings = plus.android.importClass('android.provider.Settings');
|
|
|
+ // var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
|
|
+ // var main = plus.android.runtimeMainActivity();
|
|
|
+ // main.startActivity(intent);
|
|
|
+ // }
|
|
|
+ // },
|
|
|
+ // exitApp() {
|
|
|
+ // if (plus.os.name === "Android") {
|
|
|
+ // plus.runtime.quit();
|
|
|
+ // } else {
|
|
|
+ // plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
|
|
|
+ // }
|
|
|
+ // },
|
|
|
// TODO 开屏广告 后续优化添加
|
|
|
launch() {
|
|
|
try {
|