- 使用小程序组件
- wxml 代码
<map id="mapId" zIndex="10" polyline="{{polyline}}" markers="{{markers}}" scale="16" style="width: 100%; height:100vh;" latitude="{{latitude}}" longitude="{{longitude}}">
<cover-view class="cover-view">
</cover-view>
</map>
- js代码
setMarkers() {
var that = this
wx.getLocation({
type: 'wgs84',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
var markers = [{
id: 0,
iconPath: "../../../assets/images/map.png",
latitude: that.data.latitude,
longitude: that.data.longitude,
width: 60,
height: 60
},
{
id: 1,
iconPath: "../../../assets/images/map.png",
latitude: latitude,
longitude: longitude,
width: 60,
height: 60
},
]
var polyline = [{
points: [{
latitude: that.data.latitude,
longitude: that.data.longitude,
},
{
latitude: latitude,
longitude: longitude,
},
],
color: "#FF0000DD",
width:12,
arrowLine:true,
}]
that.setData({
markers,
polyline
})
}
})
},
- 最终完成截图