官方文档

附上代码:
onLoad() {
uni.getLocation({
type: 'gcj02',
geocode:true,
success:(res)=> {
//一定要写成箭头函数!!!
this.lng = res.longitude;
this.lat = res.latitude;
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
}
});
}
在真机上面调试即可
这篇博客详细介绍了如何在uni-app中利用uni.getLocation API获取用户的当前经纬度,包括设置类型为gcj02和开启geocode选项。在真机调试下,成功获取并打印了经度和纬度,对于移动应用开发中的位置服务功能实现具有指导意义。

1万+

被折叠的 条评论
为什么被折叠?



