小栗
小栗
  • 发布:2025-06-13 09:23
  • 更新:2025-06-27 11:29
  • 阅读:144

关于地图组件拿不到中心点 getCenterLocation 问题,解决方案

分类:uni-app

可以在APP下使用 plus 5+ 方法获取

map html 5+ plus

// #ifdef APP-PLUS  
this.mapContext.$getAppMap().getCurrentCenter((state, point) => {  
    console.log(state, point);  
    if (0 == state) {  
           this.geocodeRegeo(point)  
    } else {  
          console.log("Failed!");  
    }  
    });  
// #endif  
// #ifdef H5  
this.mapContext.getCenterLocation({  
    success: (res) => {  
        this.geocodeRegeo(res)  
    }  
    });  
// #endif               
0 关注 分享

要回复文章请先登录注册

DCloud_UNI_yuhe

DCloud_UNI_yuhe

此帖子中提供了临时的解决方案: [https://ask.dcloud.net.cn/question/209825](https://ask.dcloud.net.cn/question/209825)
2025-06-27 11:29
小栗

小栗 (作者)

回复 BeforeMount :
```
this.mapContext = uni.createMapContext("map")
this.mapContext.$getAppMap()
```
### 用这里面的 $getAppMap()
2025-06-25 09:38
BeforeMount

BeforeMount

回复 BeforeMount :
this.mapContext是通过uni.createMapContext('map')获取的 还是plus.maps.getMapById('map')

const plus5map = plus.maps.getMapById('map');
plus5map.getCurrentCenter((state, point) => {
我现在这么调用的 不报错也不走回调
2025-06-19 16:08
BeforeMount

BeforeMount

你好问一下 $getAppMap()这个是什么
2025-06-19 16:06