<template>  
  <view class="content" style="width: 100%; height: 100%;">  
    <map style="width: 100%; height: 80vh;":latitude="latitude"
      :longitude="longitude"></map>  
	<button  @click="getAddress">获取定位</button>
  </view>  
</template>  
  
<script>  
export default {  
  data() {  
    return {  
		latitude: 30.909, // 初始定在首都
		longitude: 	120.39742,
      addrDel: null,  
    };  
  },  
  methods: {
  getAddress() { 
    uni.getLocation({  
      type: 'gcj02', // 根据实际情况选择是否需要此参数  wgs84,gcj02
	  isHighAccuracy: true, 
      success: (res) => {  
        console.log(res);  
        this.addrDel = res; 
		 this.latitude=res.latitude;
		 this.longitude=res.longitude;
      },  
      fail: (error) => {  
        uni.showToast({  
          title: '获取地址失败,将导致部分功能不可用',  
          icon: 'none',  
        });  
        //console.error(error); // 打印错误对象以获取更多信息  
      },  
    });  
}
},
}
</script>

我用了这上面的代码想要获取定位数据,但却老是报错显示“获取地址失败,将导致部分功能不可用”。虽然把参数改为wgs84就可以获取了,但是wgs84的精度太差了,我在老娘舅吃午饭,定位显示我在河里游泳太过分了。于是我苦思冥想想到了问题的关键,现在华为用的是鸿蒙系统,会不会是这个问题。

......还真的有,把App模块配置中Android的key换成图上的key就行了。

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐