uniapp 微信小程序 根据经纬度获取城市信息

uniapp yekong 1174℃

uniapp微信小程序开发,根据经纬度获取城市信息。

getcity(latitude, longitude) {
				var that = this;
				uni.request({
					header: {
						"Content-Type": "application/text"
					},
					//注意:这里的key值需要高德地图的 web服务生成的key  只有web服务才有逆地理编码
					url: 'https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=' + longitude + ',' +
						latitude + '&key=yourkey&radius=1000&extensions=all',
					success(re) {
						console.log(re)
						if (re.statusCode === 200) {
							that.addressname = re.data.regeocode.addressComponent.city + ' ' + re.data.regeocode
								.addressComponent.district
						} else {
							console.log("获取信息失败,请重试!")
						}
					}
				});
			}

可结合uniapp微信小程序获取当前经纬度使用

喜欢 (0)