APP&H5端获取地理位置信息
一、app端
1.在需要使用的页面中
onShow(){
//#ifdef APP-PLUS
// 获取定位信息
this.getLocations();
//#endif
},
methods:{
//获取定位信息
getPosition(){
const that = this;
uni.getLocation({
type: 'wgs84',
geocode:true,//设置该参数为true可直接获取经纬度及城市信息
success: function (res) {
console.log('获取定位信息',res);
that.latitude = res.latitude;
that.longitude = res.longitude;
that.area = res.address.city;
},
fail: function (err) {
console.log("获取定位失败",err);
uni.showToast({
title: '获取地址失败,将导致部分功能不可用',
icon:'none'
});
}
});
}
}
2.在高德地图或百度地图开放平台申请key
高德地图开放平台 https://console.amap.com/dev/key/a