- 使用小程序组件
- 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
})
}
})
},
- 最终完成截图
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210420102002982.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDIxNzcxMA==,size_16,color_FFFFFF,t_70)