map轨迹回放 uni-app errMsg "translateMarker:fail maps2.LatLng is not a constructor"

map轨迹回放 uni-app errMsg “translateMarker:fail maps2.LatLng is not a constructor”

项目信息 详情
产品分类 uniapp/H5
PC开发环境操作系统 Windows
PC开发环境操作系统版本号 Windows 11 家庭中文版 24H2
HBuilderX类型 正式
HBuilderX版本号 4.57
浏览器平台 Edge
浏览器版本 版本 134.0.3124.85 (正式版本) (64 位)
项目创建方式 HBuilderX

操作步骤:

  • 高德地图 执行回放
  • 切换vue版本 会有不同的错误

预期结果:

  • 回放

实际结果:

  • err

bug描述:

/**
 * 绘制轨迹
 */
translateMarker () {
  const points = this.polyline[0].points
  if (this.trackPlaybackIndex >= points.length) {
    console.log('轨迹回放结束')
    return
  }
  const latitude = points[this.trackPlaybackIndex].latitude
  const longitude = points[this.trackPlaybackIndex].longitude

  console.log('开始')
  // 绘制轨迹
  this.mapCtx.translateMarker({
    markerId: 1,
    // autoRotate: true,
    duration: 1000,
    destination: {
      latitude,
      longitude,
    },
    animationEnd: () => {
      this.trackPlaybackIndex++
      this.translateMarker()
      console.log('animation end')
    },
    fail: (err) => {
      console.error('绘制轨迹失败:', err)
    },
  })
},

执行代码 提示错误 errMsg:"translateMarker:fail maps2.LatLng is not a constructor"


更多关于map轨迹回放 uni-app errMsg "translateMarker:fail maps2.LatLng is not a constructor"的实战教程也可以访问 https://www.itying.com/category-93-b0.html

18 回复

这里有一个修复同类问题的临时解决方案,你可以测试一下,修改的差不多应该是你的这个问题,测试的方法是,找到下面的路径,
/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/uniapp-cli-vite/node_modules/@dcloudio/uni-h5/dist
windows路径类似
把这个 dist 文件夹 替换下面的内容。
这个是vue3版本的修复

更多关于map轨迹回放 uni-app errMsg "translateMarker:fail maps2.LatLng is not a constructor"的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我去下载Alpha版本运行看下

问题在v2 v3下又不同情况 我已经补充了截图

Alpha版本还是err 可远程查看我代码 定位情况

回复 小许同学: 光下载alpha 不行,得替换文件

回复 DCloud_UNI_yuhe: 不是很明白 预计什么时候更新修复这块问题

回复 小许同学: 找到这个文件夹替换即可以测试

回复 DCloud_UNI_yuhe: 看到了附件 我去尝试一下

const latitude = points[this.trackPlaybackIndex].latitude const longitude = points[this.trackPlaybackIndex].longitude
// longitude: 113.769089, latitude: 34.718681,

v2 能调用 v3 err v2随能调用 但是出现 第二次逻辑 end无法等到问题

你好,请提供一下完整的可以复现的代码。

代码就是这个方法 经纬度也补充了一下

请问你这个问题解决了吗

替换一下文件不能解决吗?

回复 DCloud_UNI_yuhe: 替换后又出现了新的问题 this.getProjection is not a fumction

替换后只能移动一个坐标点,运行不到animationEnd中,就开始报错了

你提供一下一个测试项目我看看

这个错误通常是由于高德地图JS API版本不兼容或未正确初始化导致的。以下是可能的原因和解决方案:

  1. 检查地图JS API版本: 确保使用的是最新版高德地图JS API(建议2.0+版本),在manifest.json中确认配置正确:
"h5": {
  "sdkConfigs": {
    "maps": {
      "amap": {
        "key": "你的高德key",
        "version": "2.0"
      }
    }
  }
}
  1. 确保地图完全初始化: 在调用translateMarker前,确认地图已加载完成:
onReady() {
  this.mapCtx = uni.createMapContext('map', this);
  // 添加延迟确保地图实例就绪
  setTimeout(() => {
    this.translateMarker();
  }, 500);
}
  1. 检查坐标数据格式: 确认points数组中的坐标格式正确,应该是:
points: [{
  latitude: 39.908,
  longitude: 116.397
},...]
  1. 降级处理: 如果仍报错,可以尝试改用moveAlong方法:
this.mapCtx.moveAlong({
  markerId: 1,
  path: this.polyline[0].points,
  duration: 3000,
  autoRotate: true
});
回到顶部