收藏
回答

行驶路径moveAlong不顺滑,为什么会有较大锯齿?

    const mapCtx = wx.createMapContext('map'this);
    mapCtx.moveAlong({
      markerId: 1,
      path: this.data.polyline[0].points,   //移动路径的坐标串
      duration: 10000,    //平滑移动的时间
      autoRotate: true    //车头按行驶方向自动旋转,默认true

    });

用的是官方示例,只是改了path的值,但出来的结果会有莫名其妙的差异,如下图

实际上应该是按公路一条直线或弧线,为什么会出现锯齿状呢?

回答关注问题邀请回答
收藏

2 个回答

  • 闪烁的凡星
    闪烁的凡星
    2021-04-15

    手机录屏地址:http://p.cecen.vip/aa.mp4

    首页点击“开始记录轨迹”按钮,程序开始每5秒记录一次位置,并将经纬度通过api.ApiInsert接口写入数据库,主要代码如下:

          wx.getLocation({
            type: 'gcj02',    //type: wgs84/gcj02
            success (res) {
              util.request(api.ApiInsert, {
                  latitude: res.latitude,
                  longitude: res.longitude,
                  speed: res.speed,
                  accuracy: res.accuracy
              },"POST").then(function (data) {
                  if (data.statusCode != 200) {
                    console.log("轨迹记录失败: " + data.message);
                  }
              });
                    }
                 })
    
    点击“停止记录轨迹”按钮时,终止以上动作。
    
    在轨迹页面中选择一个要回放的日期后进行初始化数据,主要代码如下:
        util.request(api.ApiGetLocation, {
          date: this.data.date
        }, 'GET').then(res => {
          if (res.statusCode == 200) {
            this.setData({
              location: { latitude: res.data[0].latitude, longitude: res.data[0].longitude },
              markers: [{
                id: 1,
                latitude: res.data[0].latitude,
                longitude: res.data[0].longitude,
                width: 16,
                height: 20,
                iconPath: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/car.png',
              }],
              polyline: [{
                points: res.data,
                color: '#3875FF',
                width: 6
              }]
            });
    
          }
          })
    

    初始化完数据后,当用然点确定时进行模拟回放,主要代码如下:

        const mapCtx = wx.createMapContext('map'this);
        mapCtx.moveAlong({
          markerId: 1,
          path: this.data.polyline[0].points,   //移动路径的坐标串
          duration: 10000,    //平滑移动的时间
          autoRotate: true    //车头按行驶方向自动旋转,默认true
        });
    


    前端map如下:

          <map

            class="map"
            id="map"
            latitude="{{location.latitude}}"
            longitude="{{location.longitude}}"
            markers="{{markers}}"
            polyline="{{polyline}}"
            scale="{{scale}}"
            enable-zoom="{{true}}"
            enable-scroll="{{true}}"
            showScale="{{true}}"
            showCompass="{{true}}"
          >
          </map>
    
    

    效果未达到实际要求,展示出来的路线,有些路段歪歪扭扭的,与实际不符。

    2021-04-15
    有用
    回复 4
    • Riven.
      Riven.
      2021-04-15
      代码片段在这边无法打开首页哦
      2021-04-15
      回复
    • 闪烁的凡星
      闪烁的凡星
      2021-04-16回复Riven.
      感谢,之前的APPID和密钥没对上,我修改好了,新片段地址:
      https://developers.weixin.qq.com/s/IjkVcBmC7Opp
      2021-04-16
      回复
    • Riven.
      Riven.
      2021-04-16回复闪烁的凡星
      要指定的账号才能登陆吗
      2021-04-16
      回复
    • 闪烁的凡星
      闪烁的凡星
      2021-04-16回复Riven.
      我这小程序是还没正式发布的,在开发中,是不是要把你加到体验成员中才行。你的微信号是多少?
      2021-04-16
      回复
  • Riven.
    Riven.
    2021-04-01

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2021-04-01
    有用
    回复 5
    • 闪烁的凡星
      闪烁的凡星
      2021-04-02
      代码片段分享地址:https://developers.weixin.qq.com/s/Lq91qgmz7WpN

      机型:华为荣耀V30 --- OXF-AN00

      版信版本号:8.0.1

      系统版本号:Magic 4.0.0

      Android版本:10

      谢谢。
      2021-04-02
      回复
    • 闪烁的凡星
      闪烁的凡星
      2021-04-12
      我提供的信息可以吗? 好久没收到回复。
      2021-04-12
      回复
    • Riven.
      Riven.
      2021-04-13回复闪烁的凡星
      你好,麻烦详细描述一下问题复现的流程,或者提供一下复现问题的操作录屏
      2021-04-13
      回复
    • 闪烁的凡星
      闪烁的凡星
      2021-04-15
      你好,感谢回复,具体操作我已回复在下面,请指教。
      另外,代码片段分享地址:https://developers.weixin.qq.com/s/Lq91qgmz7WpN 这地址不知你那边是否可以导入重现?
      2021-04-15
      回复
    • Riven.
      Riven.
      2021-04-15回复闪烁的凡星
      好的,这边核实下
      2021-04-15
      回复
登录 后发表内容
问题标签