详见:码云小程序demo1
1.wxml
<view
>
<view wx
:for="{{shopList}}">
{{item
.name
}}---{{item
.address
}}
<view
>{{item
.other
.distance
}}m
</view
>
<view
>{{item
.other
.duration
}}s
</view
>
</view
>
</view
>
2.js
import Router
from '../../utils/index'
import {
$getLocation
,
$chooseLocation
} from '../../utils/location'
Router({
data
: {
s_address
: '',
r_address
: '',
shopList
: [{
id
: 1,
name
: '雨花客厅店',
address
: '南京市安德门大街10号'
}, {
id
: 2,
name
: '百家湖店',
address
: '江苏省南京市双龙大道10号'
}, {
id
: 3,
name
: '淮安万达店',
address
: '江苏省宿淮安市翔宇大道100号'
}],
isok
: true
},
async onLoad() {
let req_arr
= []
this.data
.shopList
.forEach(r
=> {
let req
= this.$
get('https://apis.map.qq.com/ws/geocoder/v1/', {
address
: r
.address
,
key
: 'K2VBZ-IM5WO-V65W7-SV4SA-W4HYF-VSFD3'
})
req_arr
.push(req
)
})
let res
= await Promise
.all(req_arr
)
let from = await $getLocation()
console
.log(from);
let to
= res
.map(r
=> r
.result
.location
)
to
= to
.map(r
=> [r
.lat
, r
.lng
].join()).join(';')
console
.log(to
);
let distance
= await this.$
get('https://apis.map.qq.com/ws/distance/v1/matrix?parameters', {
key
: 'K2VBZ-IM5WO-V65W7-SV4SA-W4HYF-VSFD3',
from: [from.lat
, from.lng
].join(),
to
})
let dis_list
= distance
.result
.rows
[0].elements
this.data
.shopList
.forEach((r
, i
) => {
r
.other
= dis_list
[i
]
})
this.$
set('shopList', this.data
.shopList
)
console
.log(this.data
.shopList
);
},
}
转载请注明原文地址:https://tech.qufami.com/read-24034.html