收藏
回答

为什么我的map组件中polyline不显示?

.wxml:

<view class="map">
 <map 
     id="route_map" 
      latitude="{{latitude}}" 
      longitude="{{longitude}}" 
      style="height: 100%; width: 100%;" 
      polyline="{{polyline}}" 
      show-location="true">
 </map>
</view>
  



数据是从数据库中获取到的,下面是处理过程,打印信息。

.js:

//参数定义
data: {
    latitude39.7850456237793,
    longitude116.49617767333984,
    polyline: {
      points:[
        {Latitude39.7850456237793Longitude116.49617767333984},
        {Latitude39.78499984741211Longitude116.49617767333984},
        {Latitude39.78501892089844Longitude116.49617767333984},
        {Latitude39.78501510620117Longitude116.49617767333984},
        {Latitude39.78501892089844Longitude116.49617767333984},
        {Latitude39.785003662109375Longitude116.49617767333984},
        {Latitude39.785003662109375Longitude116.4961929321289},
        {Latitude39.78498458862305Longitude116.49620819091797},
        {Latitude39.785037994384766Longitude116.49617004394531},
        {Latitude39.785011291503906Longitude116.49617767333984},
        {Latitude39.78500747680664Longitude116.49617767333984},
        {Latitude39.78498077392578Longitude116.4961929321289},
        {Latitude39.78500747680664Longitude116.49617767333984},
        {Latitude39.78501510620117Longitude116.49617767333984},
        {Latitude39.78501510620117Longitude116.4961929321289},
        {Latitude39.785125732421875Longitude116.49617004394531},
        {Latitude39.7850227355957Longitude116.4961929321289},
        {Latitude39.78496551513672Longitude116.49620819091797},
        {Latitude39.78501510620117Longitude116.4961929321289},
        {Latitude39.78501510620117Longitude116.4961929321289},
        {Latitude39.78501510620117Longitude116.4961929321289},
        {Latitude39.78504180908203Longitude116.4961929321289},
        {Latitude39.78499984741211Longitude116.4961929321289},
        {Latitude39.785003662109375Longitude116.49620819091797},
        {Latitude39.7850341796875Longitude116.49617767333984},
        {Latitude39.78496551513672Longitude116.49620819091797},
        {Latitude39.78495407104492Longitude116.49620819091797},
        {Latitude39.784976959228516Longitude116.49620819091797},
        {Latitude39.78498458862305Longitude116.49620819091797},
        {Latitude39.78496551513672Longitude116.49620819091797},
      ],
    },
  },

//数据获取到后处理过程
successfunction (res//成功获取到值,返回一个 res 对象。
        console.log(res);
        console.log("数据长度:", res.data.length)
        //判断是否没有对应的数据
        var data_len = res.data.length;
        if (data_len == 0) {
          wx.showToast({
            title'未查到定位信息',
          })
          return
        } else {
          wx.showToast({
            title'查询成功',
            icon'success'
          })
        }
        _this.setData({
          // 将路线的起点设置为地图中心点
          latitude:res.data[0].latitude,
          longitude:res.data[0].longitude,
          // 绘制路线
          polyline: {
            points: res.data,
            color'#58c16c',
            width6,
            borderColor'#2f693c',
            borderWidth1
          }
        })
        console.log("获取到的坐标:",_this.data.polyline)
      },
      failfunction () //没有获取到值,说明这中间出问题了。
        console.log("获取失败");
      }
    })

//打印的调试信息



代码片段:https://developers.weixin.qq.com/s/tmfpabmK7VRz

最后一次编辑于  05-14
回答关注问题邀请回答
收藏

1 个回答

登录 后发表内容