diff --git a/manifest.json b/manifest.json
index abfe46b..d6b3acb 100644
--- a/manifest.json
+++ b/manifest.json
@@ -51,6 +51,14 @@
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "wx6172ec67683d31b9",
+ "requiredPrivateInfos" : [
+ "getLocation"
+ ],
+ "permission" : {
+ "scope.userLocation" : {
+ "desc" : "计算接单距离、调用导航功能"
+ }
+ },
"setting" : {
"urlCheck" : false
},
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 8de724c..5cc954e 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -29,7 +29,8 @@
- 8.34公里
+ 未知距离
+ {{formatDistance(item.order_info.lat, item.order_info.lng)}}
@@ -66,7 +67,7 @@ const toDetail = (id) => {
}
onLoad(() => {
- getList()
+ init()
})
const data = reactive({
@@ -99,6 +100,11 @@ const refreshStart = () => {
return
}
+ if (userLocation.lng === null || userLocation.lat === null) {
+ helpers.showToast('请授权位置权限')
+ return
+ }
+
refresh.interval = setInterval(() => {
refresh.rotate_deg -= 12;
}, 16);
@@ -117,6 +123,36 @@ const refreshComplete = () => {
})
}
}
+
+const userLocation = reactive({
+ lng: null,
+ lat: null,
+})
+
+//初始化
+const init = () => {
+ //获取师傅当前位置
+ uni.getLocation({
+ type: 'gcj02',
+ success(res) {
+ userLocation.lng = res.longitude
+ userLocation.lat = res.latitude
+ data.page = 1
+ getList()
+ },
+ fail(err) {
+ uni.showToast({
+ title: '请授权位置权限',
+ icon: "error"
+ })
+ }
+ });
+}
+
+const formatDistance = (lat, lng) => {
+ const res = helpers.getDistances(userLocation.lat, userLocation.lng, lat, lng);
+ return `${res.distance}${res.unit}`;
+}