uniapp: H5 は、現在の地方、都市、および道路情報を見つけます。

Gaode マップ API、H5 は、省、都市、地区の道路情報を検索します。

uniapp はuni.getLocationH5 の州、市、および地区の道路情報を取得できないため、ここでは 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
	},
});

ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/qq_40745143/article/details/131956543