Gaode マップ API、H5 は、省、都市、地区の道路情報を検索します。
uniapp はuni.getLocation
H5 の州、市、および地区の道路情報を取得できないため、ここでは AutoNavi の逆ジオコーディング インターフェイスのアドレス インターフェイスを使用して、キーと現在の緯度および経度を渡すことで州、市、および地区の道路データを取得します。
ここで注意してください: **高德地图API 申请的key,必须是WEB服务端**
、逆アドレス エンコード インターフェイスを使用できます。
uni.getLocation({
type: 'gcj02', //返回可以用于uni.openLocation的经纬度
geocode: true,
success: (res) => {
// #ifdef APP-PLUS
this.city = res.address.city;
// #endif
this.latitude = res.latitude;
this.longitude = res.longitude;
// #ifdef H5
uni.request({
url: 'https://restapi.amap.com/v3/geocode/regeo', //逆地理编码接口地址。
data: {
key: 'eb144****************f2e0c',
//location:经纬度 lng :经度 lat:纬度
location: this.longitude + ',' + this.latitude,
radius: 1000,
extensions: 'all',
batch: false,
roadlevel: 0
},
success: (res) => {
console.log(res.data);
//详细地址信息
if (res.statusCode == 200 && res.data.info == 'OK') {
this.city = res.data.regeocode.addressComponent.city
}
}
});
// #endif
},
});