小程序如何动态设置map 的markers

 data: {
        latitude: null,
        longitude: null,
        map:false,
        
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.mapCtx = wx.createMapContext('map')
        var markers =[{
            iconPath: "../../src/images/location.png",
            id: 0,
            latitude: options.latitude,
            longitude: options.longitude,
            width: 50,
            height: 50
        }];
        this.setData({
            longitude: options.longitude,
            latitude: options.latitude,
            markers:markers,
        })

现在打印markers有值 但是并不能重新渲染显示markers
怎么能动态的修改markers呢

阅读 7.4k
2 个回答
新手上路,请多包涵

遇到相同的问题,请问如何解决的

注意两个点:
1.markers已经有数据,再渲染map;
2.merkers的数据不要有非api提供的字段(多余字段)。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题