动态设置markers不显示
发布于 5 年前 作者 mingfan 992 次浏览 来自 问答

通过request的请求数据,动态加载markers在地图上不显示,有没有遇到的啊,求解啊。

5 回复

你好,请提供一下能复现问题的简单代码示例。

数据请求回来后,对数据做了markers包装,但是在map中不显示。

求解啊,大神~~

你百度就知道了

先加载完markers数据 再让 map显示 wx:if 判断一下

index.wxml:

 <map id=“map” latitude="{{latitude}}" longitude="{{longitude}}" markers="{{markers}}" bindmarkertap=“markertap” polyline="{{polyline}}" scale=“14” show-location style=“width: 100%; height:30vh ;”>

index.js

onReady:function(){

    var that = this

   console.log(‘onready’)

   wx.request({

     url: ‘http://111.207.49.73:10080/yvirtualkey-wechat-gateway/mobile/wechat/vehicle/listget’,

     data: {

       “messageheader”: {

         “timestamp”: “20171024094720”,

         “appkey”: “yesway123”,

         “version”: “1.0”

       }

     },

     header: {

       ‘content-type’: ‘application/json’

     }, method: “POST”,

     success: function (res) {

       console.log(res.data)

 

     }

   })

 

    wx.openSetting({

      success: (res) => {

        console.log(“授权结果…”)

        wx.request({

          url: ‘http://111.207.49.73:10080/yvirtualkey-wechat-gateway/mobile/wechat/vehicle/listget’,

          data: {

            “messageheader”: {

              “timestamp”: “20171024094720”,

              “appkey”: “yesway123”,

              “version”: “1.0”

            }

          },

          header: {

            ‘content-type’: ‘application/json’

          }, method: “POST”,

          success: function (res) {

            console.log(res.data)

            var json = res.data.data.list;

            var ymarker = []

            for (var i = 0; i < json.length; i++) {

              var carvalue = {};

              var item = json[i];

              carvalue.id = i;

              carvalue.latitude = item.latitude//item.latitude;

              carvalue.longitude = item.longitude//item.longitude;

              carvalue.iconPath = ‘…/image/car.png’;

              carvalue.width = 25;

              carvalue.height = 35;

              ymarker.push(carvalue)

            }

            that.setData({

              markers: ymarker

            })

            console.log(that.data.markers)

          }

        });

        wx.getLocation({

          type:‘gcj02’,

          success: function (res) {

            console.log(res.latitude + “ada” + res.longitude);

 

            that.setData({

              latitude: res.latitude,

              longitude: res.longitude,

              covers:[{

                latitude: res.latitude,

                longitude: res.longitude,

                iconPath: ‘…/image/location.png’

              }]

            })

            console.log(that.data.markers)

          }

 

        })

 

      }

    })

  }

回到顶部