Files

82 lines
2.4 KiB
JavaScript

import config from '@/utils/mapConfig';
module.exports = {
getLocation() {
return uni.getLocation({
type: 'wgs84'
})
},
getLocationPromise() {
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'wgs84',
success: (res) => {
resolve(res)
},
fail: () => {
resolve({})
}
})
})
},
getCurAddress(latitude, longitude) {
return uni.request({
url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + latitude + ',' + longitude +
'&key=' + config.key
});
},
getLocationSetting(cb) {
uni.getSetting({
success: res => {
if (!res.authSetting['scope.userLocation']) {
uni.showModal({
title: '提示',
content: '当前定位未开启,请点击确定手动开启定位',
success: response => {
if (response.confirm) {
cb && cb ()
} else {
uni.showToast({
title: '您拒绝了授权,无法获取定位服务',
duration: 2000,
icon: 'none'
})
}
}
})
}
}
})
},
openLocationSettting() {
return new Promise((resolve, reject) => {
uni.openSetting({
success: res => {
if (res.authSetting['scope.userLocation']) {
resolve()
} else {
uni.showToast({
title: '您拒绝了授权,无法获取定位服务',
duration: 2000,
icon: 'none'
})
}
},
fail: () => {
reject()
}
})
})
},
getUrlParam(url, name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = url.match(reg);
if (r != null) return (r[2]);
return null;
}
}