收藏
回答

鸿蒙系统使用MapContext.translateMarker时marker不移动

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug MapContext.translateMarker 鸿蒙客户端 8.0.11 2.21.4
// 动画到下一个点 - 关键修正
  animateToNextPoint: function() {
    if (!this.data.isPlaying || this.data.currentIndex >= this.data.trackPoints.length - 1) {
      this.setData({ isPlaying: false });
      return;
    }
    
    const currentIndex = this.data.currentIndex;
    const nextIndex = currentIndex + 1;
    const currentPoint = this.data.trackPoints[currentIndex];
    const nextPoint = this.data.trackPoints[nextIndex];
    
    // 计算距离
    const distance = this.calculateDistance(
      currentPoint.latitude, currentPoint.longitude,
      nextPoint.latitude, nextPoint.longitude
    );
    
    // 计算动画持续时间(基于速度和距离)
    const baseDuration = 1000// 基础动画时间
    const speedFactor = this.data.speedOptions[this.data.speedIndex];
    const duration = Math.max(300, baseDuration / speedFactor);
    
    // 使用translateMarker沿轨迹移动
    this.data.mapContext.translateMarker({
      markerId: 2// 移动图标标记
      destination: {
        longitude: nextPoint.longitude,
        latitude: nextPoint.latitude
      },
      autoRotate: true// 自动旋转方向
      rotate: 0,
      duration: duration,
      animationEnd: () => {
        // 更新数据
        const traveledDistance = parseFloat(this.data.traveledDistance) + distance;
        const elapsedSeconds = Math.floor((Date.now() - this.data.startTime) / 1000);
        const minutes = Math.floor(elapsedSeconds / 60);
        const seconds = elapsedSeconds % 60;
        const elapsedTime = `${minutes.toString().padStart(2'0')}:${seconds.toString().padStart(2'0')}`;
        const progress = ((nextIndex + 1) / this.data.trackPoints.length * 100).toFixed(1);
        
        this.setData({
          currentIndex: nextIndex,
          longitude: nextPoint.longitude,
          latitude: nextPoint.latitude,
          currentSpeed: nextPoint.speed,
          currentPosition: `经度:${nextPoint.longitude.toFixed(6)}\n纬度:${nextPoint.latitude.toFixed(6)}`,
          traveledDistance: traveledDistance.toFixed(2),
          elapsedTime,
          progress
        });
        
        // 继续下一个点
        if (nextIndex < this.data.trackPoints.length - 1) {
          this.data.animationTimer = setTimeout(() => {
            this.animateToNextPoint();
          }, 50); // 短暂延迟确保动画流畅
        } else {
          this.setData({ 
            isPlaying: false,
            currentSpeed: 0 
          });
          wx.showToast({
            title: '轨迹回放完成',
            icon: 'success'
          });
        }
      }
    });
  },
回答关注问题邀请回答
收藏

3 个回答

  • 社区技术运营专员--阳光
    社区技术运营专员--阳光
    2025-10-23

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2025-10-23
    有用
    回复 3
  • 杲杲冬日光
    杲杲冬日光
    2025-10-23

    不管是ios还是安卓都可以正常使用,只有鸿蒙不能进入MapContext.translateMarker

    

    2025-10-23
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-10-23
    有用
登录 后发表内容