看文档markers应该是个数组,我手动添加数组是能正常显示的,但是通过访问接口的success回调时push到数组新的内容时,地图上的所有标记都不显示了,这是什么情况啊,以下是代码:
var markers = [{
id: '0',
latitude: 36.18359383595297,
longitude: 120.37397938541415,
iconPath: '/assets/images/wxapp-scale-code-img@2x.png',
width: 140,
height: 36,
title: "培训学校1"
}, {
id: '1',
latitude: 36.188841352893085,
longitude: 120.37724095157625,
iconPath: '/assets/images/wxapp-scale-code-img@2x.png',
width: 140,
height: 36,
title: "培训学校2"
}]
Page({
data: {
scale: 14,
markers: markers
}
}),
onLoad: function() {
var _this = this;
wx.getLocation({
type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
success: function(res) {
console.log(res)
_this.setData({
latitude: res.latitude,
longitude: res.longitude,
markers: markers.push({
id: "2",
latitude: 36.187611768251,
longitude: 120.38160222343447,
width: 30,
height: 30,
iconPath: "/assets/images/walk@2x.png",
title: "当前位置"
}),
});
}
})
},