uniapp 小程序 高德/腾讯逆地点解析

打印 上一主题 下一主题

主题 1536|帖子 1536|积分 4608

**
1.微信小程序先获取getLocationAPI权限
2.manifest.json文件中加上

“permission” : {
“scope.userLocation” : {
“desc” : “你的位置将用于小程序位置接口的效果展示”
}
},
“requiredPrivateInfos” : [ “getLocation” ]
高德

getLocation() {
uni.getLocation({
type: ‘wgs84’,
success: (res) => {
this.latitude = res.latitude
this.longitude = res.longitude
this.reverseGeocode(res.latitude, res.longitude);
},
fail: (err) => {
this.error = err;
console.error(‘定位失败:’, err);
}
});
},
// 逆地理编码函数
reverseGeocode(latitude, longitude) {
const key = 'xxxxx; // 换成你自己的AppKey
const url = https://restapi.amap.com/v3/geocode/regeo?key=${key}&location=${longitude},${latitude};
uni.request({
url: url,
method: ‘GET’,
success: (res) => {
if (res.statusCode === 200 && res.data.status === ‘1’) {
// res.data.regeocode.addressComponent.province + res.data.regeocode.addressComponent.city +
this.location = res.data.regeocode.addressComponent.streetNumber.street + res.data
.regeocode.addressComponent.streetNumber.number,
this.pageNo = 1
this.indexList()
} else {
console.error(‘逆地理编码失败:’, res.data);
}
},
fail: (error) => {
console.error(‘哀求失败:’, error);
}
});
},
腾讯

var QQMapWx = require(‘@/utils/qqmap-wx-jssdk.min.js’)
// 文件下载地点https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview
var qqMapSdk = new QQMapWx({
key: ‘XXXXXX’
})
getLocation() {
uni.getLocation({
type: ‘wgs84’,
success: (res) => {
this.latitude = res.latitude
this.longitude = res.longitude
this.reverseGeocode(res.latitude, res.longitude);
},
fail: (err) => {
this.error = err;
console.error(‘定位失败:’, err);
}
});
},
// 逆地理编码函数
reverseGeocode(latitude, longitude) {
qqMapSdk.reverseGeocoder(({
location: {
latitude: latitude,
longitude: longitude,
},
success: (res) => {
this.location = res.result.address_component.street_number
},
fail: (error) => {
console.log(error)
}
}))
},
注意:
1.腾讯开发认证企业并分配逆地点解析配额
2.微信开放平台设置腾讯域名

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

前进之路

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表