uniapp:H5定位当前省市区街道信息

高德地图api,H5定位省市区街道信息。

由于uniapp的uni.getLocation在H5不能获取到省市区街道信息,所以这里使用高德的逆地理编码接口地址接口,通过传key和当前经纬度,获取到省市区街道数据。

这里需要注意的是:**高德地图API 申请的key,必须是WEB服务端**,才可以使用逆地址编码接口。

js 复制代码
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
	},
});
相关推荐
用户6990304848754 天前
try catch使用场景 处理同步代码错误兼容用的
javascript·uni-app
ITKEY_4 天前
uniapp微信开发者工具 更改AppID失败 touristappid
uni-app
Geek_Vison5 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas
CHB5 天前
HDC2026 演讲实录|AI 驱动的跨端进化:利用 uni-agent 快速构建高性能鸿蒙应用
uni-app·harmonyos
2501_915918416 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
斯内普吖6 天前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源
海阔天空66886 天前
uniapp开启调试模式
uni-app·uniapp开启调试模式
anyup6 天前
分享 5 套 uni-app 实用主题,一键适配暗黑模式
前端·uni-app·视觉设计
gg159357284607 天前
Uni-app跨平台开发全解课程:从零基础到企业级多端落地实战
vue.js·uni-app
xshirleyl8 天前
uniapp小兔鲜儿day3
uni-app