本文主要是介绍uniapp 获取地理位置(uni#getLocation和高德sdk获取中文地址),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考
https://uniapp.dcloud.net.cn/api/location/location.html
https://ask.dcloud.net.cn/article/35070
1. uniapp api获取经纬度
uni.getLocation({type: 'wgs84',success: function (res) {console.log('当前位置的经度:' + res.longitude);console.log('当前位置的纬度:' + res.latitude);}
});
2. 高德api获取中文地理信息
- 高德平台注册key
- 下载高德微信小程序sdk
- 创建并使用
3.1 创建uniapp
3.2 创建common目录
3.3 sdk解压,添加到common
3.4 使用:data[0].name
对应中文地址,比如武汉市江汉区xx路xx号
import amap from '../../common/amap-wx.130.js';export default {data() {return {amapPlugin: null, key: '你自己申请的key' }},onLoad() { this.amapPlugin = new amap.AMapWX({ key: this.key });},methods: {getLocation() {uni.showLoading({ title: '获取信息中' }); this.amapPlugin.getRegeo({ success: (data) => { console.log(data[0].name) uni.hideLoading(); } }); }}
这篇关于uniapp 获取地理位置(uni#getLocation和高德sdk获取中文地址)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!