哪位指点一下,想弄个多点标记。并且点击标记点能直接导航,现在做的只能导航同一个标记点!
小程序的微信开发文档有说明的
你可以使用微信小程序的地图组件来实现多点标记和导航功能。具体步骤如下:
<map id="myMap" latitude="{{latitude}}" longitude="{{longitude}}" scale="{{scale}}"></map>
wx.getLocation({
type: 'gcj02',
success: (res) => {
this.setData({
latitude: res.latitude,
longitude: res.longitude
})
}
})
wx.getLocation({
type: 'gcj02',
success: (res) => {
this.setData({
latitude: res.latitude,
longitude: res.longitude
})
// 添加标记点
const markers = [{
id: 1,
latitude: res.latitude,
longitude: res.longitude,
title: '我的位置'
}, {
id: 2,
latitude: res.latitude + 0.01,
longitude: res.longitude + 0.01,
title: '标记点1'
}, {
id: 3,
latitude: res.latitude - 0.01,
longitude: res.longitude - 0.01,
title: '标记点2'
}]
this.setData({
markers: markers
})
}
})
<map id="myMap" latitude="{{latitude}}" longitude="{{longitude}}" scale="{{scale}}" bindmarkertap="onMarkerTap" markers="{{markers}}"></map>
onMarkerTap(e) {
const markerId = e.markerId
const marker = this.data.markers.filter((marker) => marker.id === markerId)[0]
wx.openLocation({
latitude: marker.latitude,
longitude: marker.longitude,
name: marker.title
})
}
以上就是实现微信小程序多点标记和导航功能的思路和示例代码。