今天做个地图显示当前位置,开始的时候markers没有出现在地图上,
看看控制器时发现markers和经纬度并没有在map标签上渲染出来,但是在data里却看到有markers和经纬度数据, 下面直接上代码
<map
wx:if="{{mapShow}}"
style="width: 100%; height: 100%;"
latitude="{{latitude}}"
longitude="{{longitude}}"
markers="{{markers}}"
></map>
data: {
scale: 18,
latitude: '',
longitude: '',
mapShow: false
},
onLoad: function () {
let that = this
wx.getLocation({
type: 'gcj02',
success(res) {
const latitude = res.latitude
const longitude = res.longitude
const markers= [{
id: 1,
latitude: latitude,
longitude: longitude,
width: 50,
height: 50,
iconPath: '/images/icon/location.png',
}];
that.setData({
latitude: latitude,
longitude: longitude,
markers: markers
})
}
});
},