【调整】因腾讯获取高精度坐标接口【wx.getLocation】非常难申请,而导致功能可能受影响,使用【wx.getFuzzyLocation】模糊获取经纬度,但是确实是模糊的,精度不够高,误差有点大;

This commit is contained in:
大灰灰
2022-10-31 22:00:43 +08:00
parent fde4b53797
commit 93e195f0a5
6 changed files with 371 additions and 202 deletions

View File

@@ -1,179 +1,179 @@
{ {
"name" : "核心商城系统", "name": "核心商城系统",
"appid" : "__UNI__EAACF14", "appid": "__UNI__EAACF14",
"description" : "核心商城系统CoreShop是基于uni-app框架开发的商城应用程序", "description": "核心商城系统CoreShop是基于uni-app框架开发的商城应用程序",
"versionName" : "1.0", "versionName": "1.0",
"versionCode" : 1, "versionCode": 1,
"transformPx" : false, "transformPx": false,
"app-plus" : { "app-plus": {
/* 5+App */ /* 5+App */
"modules" : { "modules": {
"Payment" : {}, "Payment": {},
"VideoPlayer" : {}, "VideoPlayer": {},
"Maps" : {} "Maps": {}
},
/* */
"distribute": {
/* */
"android": {
/* android */
"permissions": [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters": [ "armeabi-v7a", "arm64-v8a", "x86" ]
},
"ios": {},
/* ios */
"sdkConfigs": {
"payment": {
"weixin": {
"appid": "wx11d95cdaee6058f6"
}
}, },
/* */ "ad": {},
"distribute" : { "maps": {
/* */ "amap": {
"android" : { "appkey_ios": "91b94ecb48605c4e048aa1971459eca7",
/* android */ "appkey_android": "91b94ecb48605c4e048aa1971459eca7"
"permissions" : [ }
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CALL_PHONE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.INTERNET\"/>",
"<uses-permission android:name=\"android.permission.MODIFY_AUDIO_SETTINGS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_CONTACTS\"/>",
"<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
},
"ios" : {},
/* ios */
"sdkConfigs" : {
"payment" : {
"weixin" : {
"appid" : "wx11d95cdaee6058f6"
}
},
"ad" : {},
"maps" : {
"amap" : {
"appkey_ios" : "91b94ecb48605c4e048aa1971459eca7",
"appkey_android" : "91b94ecb48605c4e048aa1971459eca7"
}
},
"oauth" : {
"univerify" : {}
},
"share" : {}
},
"icons" : {
"android" : {
"hdpi" : "",
"xhdpi" : "",
"xxhdpi" : "",
"xxxhdpi" : ""
},
"ios" : {
"appstore" : "",
"ipad" : {
"app" : "",
"app@2x" : "",
"notification" : "",
"notification@2x" : "",
"proapp@2x" : "",
"settings" : "",
"settings@2x" : "",
"spotlight" : "",
"spotlight@2x" : ""
},
"iphone" : {
"app@2x" : "",
"app@3x" : "",
"notification@2x" : "",
"notification@3x" : "",
"settings@2x" : "",
"settings@3x" : "",
"spotlight@2x" : "",
"spotlight@3x" : ""
}
}
}
}, },
"splashscreen" : { "oauth": {
"waiting" : true "univerify": {}
},
"share": {}
},
"icons": {
"android": {
"hdpi": "",
"xhdpi": "",
"xxhdpi": "",
"xxxhdpi": ""
},
"ios": {
"appstore": "",
"ipad": {
"app": "",
"app@2x": "",
"notification": "",
"notification@2x": "",
"proapp@2x": "",
"settings": "",
"settings@2x": "",
"spotlight": "",
"spotlight@2x": ""
},
"iphone": {
"app@2x": "",
"app@3x": "",
"notification@2x": "",
"notification@3x": "",
"settings@2x": "",
"settings@3x": "",
"spotlight@2x": "",
"spotlight@3x": ""
}
} }
}
}, },
/* SDK */ "splashscreen": {
"quickapp" : {}, "waiting": true
/* */ }
"mp-weixin" : { },
"appid" : "wx6fc139d4de0b470f", /* SDK */
"setting" : { "quickapp": {},
"urlCheck" : true, /* */
"postcss" : true, "mp-weixin": {
"minified" : true, "appid": "wx6fc139d4de0b470f",
"es6" : true, "setting": {
"checkSiteMap" : false "urlCheck": true,
}, "postcss": true,
"plugins" : { "minified": true,
"chooseLocation" : { "es6": true,
"version" : "1.0.9", "checkSiteMap": false
"provider" : "wx76a9a06e5b4e693e"
}
},
"permission" : {
"scope.userLocation" : {
"desc" : "你的位置信息将用于小程序定位"
}
},
"optimization" : {
"subPackages" : true
},
"requiredPrivateInfos" : [ "getLocation", "chooseAddress" ]
}, },
"h5" : { "plugins": {
"title" : "南山田舍", "chooseLocation": {
"domain" : "https://h5.coreshop.coreshop.net", "version": "1.0.9",
"router" : { "provider": "wx76a9a06e5b4e693e"
"base" : "./", }
"mode" : "hash" },
}, "permission": {
"template" : "index.html", "scope.userLocation": {
"devServer" : { "desc": "你的位置信息将用于小程序定位"
"port" : 80, }
"disableHostCheck" : true, },
"https" : true "optimization": {
}, "subPackages": true
"sdkConfigs" : { },
"maps" : { "requiredPrivateInfos": [ "getFuzzyLocation", "chooseAddress" ]
"qqmap" : { },
"key" : "AEIBZ-H5TRI-A6VGA-5KRNA-QKKK6-JGB33" "h5": {
} "title": "南山田舍",
} "domain": "https://h5.demo.coreshop.cn",
}, "router": {
"optimization" : { "base": "./",
"treeShaking" : { "mode": "hash"
"enable" : false },
} "template": "index.html",
"devServer": {
"port": 80,
"disableHostCheck": true,
"https": true
},
"sdkConfigs": {
"maps": {
"qqmap": {
"key": "AEIBZ-H5TRI-A6VGA-5KRNA-QKKK6-JGB33"
} }
}
}, },
"mp-toutiao" : { "optimization": {
"setting" : { "treeShaking": {
"es6" : true, "enable": false
"postcss" : true, }
"minified" : true }
}, },
"appid" : "" "mp-toutiao": {
"setting": {
"es6": true,
"postcss": true,
"minified": true
}, },
"mp-qq" : { "appid": ""
"setting" : { },
"es6" : true, "mp-qq": {
"postcss" : true, "setting": {
"minified" : true "es6": true,
}, "postcss": true,
"optimization" : { "minified": true
"subPackages" : true
}
}, },
"mp-alipay" : {}, "optimization": {
"mp-baidu" : {} "subPackages": true
}
},
"mp-alipay": {},
"mp-baidu": {}
} }

View File

@@ -10,6 +10,11 @@
<view slot="right"> <view slot="right">
</view> </view>
</u-navbar> </u-navbar>
<view class="coreshop-padding-10" v-if="alert.show">
<u-alert :title="alert.title" type="error" :description="alert.description" effect="dark"></u-alert>
</view>
<view class="coreshop-padding-10"> <view class="coreshop-padding-10">
<u--form :model="form" :rules="rules" ref="uForm" errorType="message" labelPosition="left" labelWidth="80"> <u--form :model="form" :rules="rules" ref="uForm" errorType="message" labelPosition="left" labelWidth="80">
<u-form-item label="收货人" prop="name" borderBottom clearValidate> <u-form-item label="收货人" prop="name" borderBottom clearValidate>
@@ -78,6 +83,9 @@
<view class="coreshop-bottomBox"> <view class="coreshop-bottomBox">
<button class="coreshop-btn coreshop-btn-square coreshop-btn-w" @click="delShip" v-if="id && id != 0" :disabled='submitStatus' :loading='submitStatus'>删除</button> <button class="coreshop-btn coreshop-btn-square coreshop-btn-w" @click="delShip" v-if="id && id != 0" :disabled='submitStatus' :loading='submitStatus'>删除</button>
<!-- #ifdef MP-WEIXIN -->
<button class="coreshop-btn coreshop-btn-square coreshop-btn-b" @click="wechatAddress" hover-class="btn-hover2">从微信获取</button>
<!-- #endif -->
<button class="coreshop-btn coreshop-btn-square coreshop-btn-b" @click="saveShip" :disabled='submitStatus' :loading='submitStatus'>保存</button> <button class="coreshop-btn coreshop-btn-square coreshop-btn-b" @click="saveShip" :disabled='submitStatus' :loading='submitStatus'>保存</button>
</view> </view>
</view> </view>
@@ -158,10 +166,15 @@
} }
] ]
}, },
alert: {
title: '获取定位失败,请检查是否开启定位功能。',
description: '未获取到您的经纬度坐标,我们需要获取您的经纬度坐标,来计算与发货点的配送距离。不然无法开启同城配送计算运费。',
closable: true,
show: false
},
} }
}, },
onShow() { onShow() {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
const chooseLocation = requirePlugin('chooseLocation'); const chooseLocation = requirePlugin('chooseLocation');
const location = chooseLocation.getLocation(); const location = chooseLocation.getLocation();
@@ -208,17 +221,32 @@
// 获取自己的位置信息 // 获取自己的位置信息
getMyLocation() { getMyLocation() {
let _this = this; let _this = this;
// #ifdef MP-WEIXIN
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
_this.latitude = res.latitude
_this.longitude = res.longitude
console.log('当前位置的经度1' + res);
},
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
}
})
// #endif
// #ifndef MP-WEIXIN
uni.getLocation({ uni.getLocation({
type: 'wgs84', type: 'wgs84',
success: function (res) { success: function (res) {
_this.longitude = res.longitude; _this.longitude = res.longitude;
_this.latitude = res.latitude; _this.latitude = res.latitude;
console.log('当前位置的经度2' + res);
}, },
fail: function () { fail: function () {
_this.$u.toast("获取位置信息失败") _this.$u.toast("获取您的经纬度坐标失败")
} }
}); });
// #endif
}, },
onConfirm(e) { onConfirm(e) {
console.log(e); console.log(e);
@@ -442,10 +470,33 @@
} }
}); });
// #endif // #endif
},
// #ifdef MP-WEIXIN
wechatAddress: function () {
let _that = this;
wx.chooseAddress({
success: res => {
if (res.errMsg == "chooseAddress:ok") {
//获取成功
//存储这个收获地区信息到数据库
let data = {
provinceName: res.provinceName,
cityName: res.cityName,
countyName: res.countyName,
postalCode: res.postalCode
};
console.log(res);
}
} else {
this.$refs.uToast.show({ title: '获取微信地址失败', type: 'error' });
}
}
});
},
// #endif
}, },

View File

@@ -251,30 +251,37 @@
}, },
// 查询现在的位置 // 查询现在的位置
getLocation() { getLocation() {
let this_ = this let _this = this;
uni.getLocation({ // #ifdef MP-WEIXIN
// type: 'gcj02', // 返回国测局坐标 wx.getFuzzyLocation({
geocode: true, type: 'wgs84',
success: function (res) { success(res) {
this_.initMap(res) _this.initMap(res)
//console.log(res);
}, },
fail: function (e) { fail: function () {
uni.showToast({ _this.$u.toast("获取您的经纬度坐标失败")
icon: 'none',
title: '获取地址失败, 请检查是否开启定位权限~~'
})
} }
}) })
// #endif
// #ifndef MP-WEIXIN
uni.getLocation({
type: 'wgs84',
success: function (res) {
_this.initMap(res)
},
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
}
});
// #endif
}, },
// 查询现在的位置 // 查询现在的位置
getOldLocation(longitude, latitude) { getOldLocation(longitude, latitude) {
let this_ = this;
var res = { var res = {
longitude: longitude, longitude: longitude,
latitude: latitude latitude: latitude
} }
this_.initMap(res) this.initMap(res)
}, },
// 初始化我的位置 // 初始化我的位置
async initMap(res) { async initMap(res) {

View File

@@ -64,11 +64,52 @@
//获取门店列表 //获取门店列表
getStoreAddress() { getStoreAddress() {
let _this = this; let _this = this;
// #ifdef MP-WEIXIN
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
_this.latitude = res.latitude
_this.longitude = res.longitude
console.log('当前位置的经度1' + res);
},
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
},
complete: function (res) {
if (!_this.longitude || !_this.latitude) {
_this.longitude = '0';
_this.latitude = '0';
}
let data = {
'key': _this.key,
'longitude': _this.longitude,
'latitude': _this.latitude,
'page': _this.page,
'limit': _this.limit,
}
_this.$u.api.storeList(data).then(e => {
if (e.status) {
console.log(e);
_this.storeList = [..._this.storeList, ...e.data]
} else {
_this.$u.toast("门店数据获取失败。");
}
});
}
})
// #endif
// #ifndef MP-WEIXIN
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'wgs84',
success: function (res) { success: function (res) {
_this.longitude = res.longitude; _this.longitude = res.longitude;
_this.latitude = res.latitude; _this.latitude = res.latitude;
console.log('当前位置的经度2' + res);
},
fail: function () {
_this.latitude = 0;
_this.longitude = 0;
_this.$u.toast("获取您的经纬度坐标失败")
}, },
complete: function (res) { complete: function (res) {
let data = { let data = {
@@ -88,6 +129,7 @@
}); });
} }
}); });
// #endif
}, },
} }
}; };

View File

@@ -83,12 +83,50 @@
//获取门店列表 //获取门店列表
getStoreList() { getStoreList() {
let _this = this; let _this = this;
// #ifdef MP-WEIXIN
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
_this.latitude = res.latitude
_this.longitude = res.longitude
console.log('当前位置的经度1' + res);
},
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
},
complete: function (res) {
if (!_this.longitude || !_this.latitude) {
_this.longitude = '0';
_this.latitude = '0';
}
let data = {
'key': _this.key,
'longitude': _this.longitude,
'latitude': _this.latitude,
'page': _this.page,
'limit': _this.limit,
}
_this.$u.api.storeList(data).then(e => {
if (e.status) {
console.log(e);
_this.storeList = [..._this.storeList, ...e.data]
} else {
_this.$u.toast("门店数据获取失败。");
}
});
}
})
// #endif
// #ifndef MP-WEIXIN
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'wgs84',
success: function (res) { success: function (res) {
_this.longitude = res.longitude; _this.longitude = res.longitude;
_this.latitude = res.latitude; _this.latitude = res.latitude;
}, },
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
},
complete: function (res) { complete: function (res) {
if (!_this.longitude || !_this.latitude) { if (!_this.longitude || !_this.latitude) {
_this.longitude = '0'; _this.longitude = '0';
@@ -111,6 +149,7 @@
}); });
} }
}); });
// #endif
}, },
//门店选择 //门店选择
selectStore(id, name, mobile, address) { selectStore(id, name, mobile, address) {

View File

@@ -78,6 +78,27 @@
// 获取自己的位置信息 // 获取自己的位置信息
getMyLocation() { getMyLocation() {
let _this = this; let _this = this;
// #ifdef MP-WEIXIN
wx.getFuzzyLocation({
type: 'wgs84',
success(res) {
_this.longitude = res.longitude;
_this.latitude = res.latitude;
_this.getStoreList();
},
fail: function () {
_this.$u.toast("获取您的经纬度坐标失败")
},
complete: function (res) {
if (!_this.longitude || !_this.latitude) {
_this.longitude = '0';
_this.latitude = '0';
}
_this.getStoreList();
}
})
// #endif
// #ifndef MP-WEIXIN
uni.getLocation({ uni.getLocation({
type: 'wgs84', type: 'wgs84',
success: function (res) { success: function (res) {
@@ -86,36 +107,45 @@
_this.getStoreList(); _this.getStoreList();
}, },
fail: function () { fail: function () {
_this.$u.toast("获取位置信息失败") _this.$u.toast("获取您的经纬度坐标失败")
},
complete: function (res) {
if (!_this.longitude || !_this.latitude) {
_this.longitude = '0';
_this.latitude = '0';
}
_this.getStoreList();
} }
}); });
// #endif
}, },
// 获取店铺列表信息 // 获取店铺列表信息
getStoreList() { getStoreList() {
let _this = this; let _this = this;
let data = { let data = {
'longitude': _this.longitude, 'longitude': _this.longitude,
'latitude': _this.latitude, 'latitude': _this.latitude,
'page': _this.page, 'page': _this.page,
'limit': _this.limit, 'limit': _this.limit,
} }
_this.$u.api.storeList(data).then(res => { _this.$u.api.storeList(data).then(res => {
if (res.status) { if (res.status) {
_this.storeList = res.data; _this.storeList = res.data;
let storeList = res.data; let storeList = res.data;
for (let i = 0; i < storeList.length; i++) { if (storeList.length > 0) {
let mark = { _this.longitude = storeList[0].longitude;
id: storeList[i].id, _this.latitude = storeList[0].latitude;
latitude: storeList[i].latitude, for (let i = 0; i < storeList.length; i++) {
longitude: storeList[i].longitude, let mark = {
iconPath: '/static/images/map/location.png', id: storeList[i].id,
width: 15, latitude: storeList[i].latitude,
height: 23, longitude: storeList[i].longitude,
iconPath: '/static/images/map/location.png',
width: 15,
height: 23,
}
_this.covers.push(mark);
} }
_this.covers.push(mark);
} }
} else { } else {
_this.$u.toast("门店信息获取失败") _this.$u.toast("门店信息获取失败")