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'
			});
		}
	});
},

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

相关推荐
我叫汪枫17 小时前
前端物理引擎库推荐 - 让你的网页动起来!
前端
百思可瑞教育18 小时前
uni-app 根据用户不同身份显示不同的tabBar
vue.js·uni-app·北京百思可瑞教育·北京百思教育
雾恋1 天前
最近一年的感悟
前端·javascript·程序员
A黄俊辉A1 天前
axios+ts封装
开发语言·前端·javascript
小李小李不讲道理1 天前
「Ant Design 组件库探索」四:Input组件
前端·javascript·react.js
连合机器人1 天前
晨曦中的守望者:当科技为景区赋予温度
java·前端·科技
郑板桥301 天前
tua-body-scroll-lock踩坑记录
前端·javascript
慢半拍iii1 天前
JAVA Web —— A / 网页开发基础
前端
Q_Q19632884751 天前
python+springboot+uniapp微信小程序题库系统 在线答题 题目分类 错题本管理 学习记录查询系统
spring boot·python·django·uni-app·node.js·php
gnip1 天前
pnpm 的 monorepo架构多包管理
前端·javascript