参考
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();
}
});
}
}