Browse Source

定位到最近的广场

soldDate
HolyKnightIX 1 year ago
parent
commit
d9a214ff26
2 changed files with 27 additions and 15 deletions
  1. +24
    -15
      index/index.js
  2. +3
    -0
      index/index.ttss

+ 24
- 15
index/index.js View File

@@ -158,9 +158,9 @@ Page({
}) })
}, },


bindPickerChange(e) {
const index = e.detail.value
const mallTenantId = this.data.shopList[index].tenantId
bindPickerChange(e, indexIn, id) {
const index = indexIn || e.detail.value
const mallTenantId = id || this.data.shopList[index].tenantId
tt.setStorageSync('mallTenantId', mallTenantId) tt.setStorageSync('mallTenantId', mallTenantId)
tt.setStorageSync('mallIndex', index) tt.setStorageSync('mallIndex', index)
this.setData({ this.setData({
@@ -630,8 +630,8 @@ Page({
const longitudeNow = that.data.locateData.longitude const longitudeNow = that.data.locateData.longitude


const mallLocationArr = [] const mallLocationArr = []
let index = 0
that.data.shopList.forEach(item => {
that.data.shopList.forEach((item, index) => {
const obj = { const obj = {
latitude: item.latitude, latitude: item.latitude,
longitude: item.longitude, longitude: item.longitude,
@@ -639,17 +639,28 @@ Page({
index: index index: index
} }
mallLocationArr.push(obj) mallLocationArr.push(obj)
index++
}) })


const isBest = []
mallLocationArr.forEach(item => {
const num = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude)
isBest.push(num.distance)
const tempArr = that.data.shopList
const bloobArr = []
mallLocationArr.forEach((item, index) => {
const distanceData = that.getDistances(latitudeNow, longitudeNow, item.latitude, item.longitude)
tempArr[index].distance = distanceData.distance
bloobArr.push(distanceData.distance)
})
that.setData({
shopList: tempArr
})
const nearestDistance = that.bloob(bloobArr)[0]
const nearestArr = that.data.shopList.filter((item, index) => {
if (item.distance == nearestDistance) {
that.bindPickerChange('', index, item.tenantId)
return true
} else {
return false
}
}) })
console.log(isBest, 'isBest');
const winer = this.bloob(isBest)
console.log(winer, 'winer');
console.log(nearestArr[0], 'nearestArr');
} }
}) })


@@ -697,9 +708,7 @@ Page({
let temp = tempArr[j]; let temp = tempArr[j];
tempArr[j] = tempArr[j + 1]; tempArr[j] = tempArr[j + 1];
tempArr[j + 1] = temp; tempArr[j + 1] = temp;

} }

} }
} }
return tempArr return tempArr


+ 3
- 0
index/index.ttss View File

@@ -130,6 +130,9 @@ page {
margin-right: 10rpx; margin-right: 10rpx;
} }


.distance_str {
margin-left: 10rpx;
}


.right { .right {
position: relative; position: relative;


Loading…
Cancel
Save