收藏
回答

moveToLocation报错”fail:mapview is null“,无法移置当前定位点?

8月前上线的时候,开发工具和真机测试功能都是正常的,近期测试的时候发现该功能在开发工具中正常,真机异常,并提示错误{"errMsg":"moveToMapLocation:fail:mapview is null")

以下是代码片段:

onReady() {
    this.initMapContext();
},
methods: {
    initMapContext() {
      const query = uni.createSelectorQuery().in(this);
      query
        .select("#map")
        .fields({ context: true }, (res) => {
          if (res.context) {
            this.mapCtx = res.context;
          }
        })
        .exec();
    },
      goToCurrentLocation() {
      this.mapCtx.moveToLocation();
    }
}
回答关注问题邀请回答
收藏

3 个回答

  • 社区技术运营专员-Jahozheng
    社区技术运营专员-Jahozheng
    2025-09-19

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

    2025-09-19
    有用
    回复
  • Mandyᴸⁱ
    Mandyᴸⁱ
    2025-11-14

    已经解决了,官方回答都是片面的。


    只需要在调用失败的时候,延迟1秒在循环调用就可以了。


    可能是部分手机性能不佳导致第一次moveToLocation失败

    2025-11-14
    有用
    回复
  • 智能回答 智能回答 本次回答由AI生成
    2025-09-17
    有用
    回复
登录 后发表内容