uniApp获取实时定位

通过你获取的key放到项目manifest.json里面,对应填写你所需要的key值,还有高德用户名

用户名:

key值的位置:

代码:

html:

html 复制代码
<view class="intList pdNone">
	<view class="label">详细地址</view>
	<uni-easyinput @iconClick="goLocalAddress" placeholder="请点击图标获取详细地址" v-model="form.address" />
</view>

js:

javascript 复制代码
goLocalAddress() {
	uni.showLoading({
		title: '获取中...'
	})
		let _this = this
		uni.getLocation({
			geocode: true,
			type: 'gcj02',
			success: (res) => {
				uni.hideLoading()
				this.form.address = res.address.poiName || res.address.street
				this.form.longitude = res.longitude
				this.form.latitude = res.latitude
			},
			fail: function(e) {
				uni.hideLoading()
				uni.getNetworkType({
				success: (res) => {},
					fail: () => {
						uni.showModal({
							content: '获取失败!',
							showCancel: false
						})
					}
				})
			uni.showToast({
				title: JSON.stringify(e),
				icon: 'none'
			});
		}
	});
},

效果:点击图标可直接获取当前位置

相关推荐
扶苏10021 天前
Vue 3 响应式原理深度解析
前端·javascript·vue.js
NEXT061 天前
React 性能优化:图片懒加载
前端·react.js·面试
PineappleCoder1 天前
别让字体拖了后腿:FOIT/FOUT 深度解析与字体加载优化全攻略
前端·性能优化
NEXT061 天前
后端跑路了怎么办?前端工程师用 Mock.js 自救实录
前端·后端·程序员
装不满的克莱因瓶1 天前
Java7新特性:try-with-resources写法
java·前端·javascript·jdk·新特性·jdk7
SailingCoder1 天前
【 从“打补丁“到“换思路“ 】一次企业级 AI Agent 的架构拐点
大数据·前端·人工智能·面试·架构·agent
~央千澈~1 天前
抖音弹幕游戏开发之第12集:添加冷却时间机制·优雅草云桧·卓伊凡
java·服务器·前端
CappuccinoRose1 天前
CSS 语法学习文档(十三)
前端·css·学习·postcss·模块化·预处理器
OpenTiny社区1 天前
Angular Module→Standalone 架构进化解析
前端·架构·angular.js
哆啦A梦15881 天前
Vue3魔法手册 作者 张天禹 06_监控
前端·vue.js·typescript