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

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

相关推荐
zwjapple4 小时前
docker-compose一键部署全栈项目。springboot后端,react前端
前端·spring boot·docker
像风一样自由20206 小时前
HTML与JavaScript:构建动态交互式Web页面的基石
前端·javascript·html
aiprtem7 小时前
基于Flutter的web登录设计
前端·flutter
浪裡遊7 小时前
React Hooks全面解析:从基础到高级的实用指南
开发语言·前端·javascript·react.js·node.js·ecmascript·php
why技术7 小时前
Stack Overflow,轰然倒下!
前端·人工智能·后端
GISer_Jing7 小时前
0704-0706上海,又聚上了
前端·新浪微博
止观止8 小时前
深入探索 pnpm:高效磁盘利用与灵活的包管理解决方案
前端·pnpm·前端工程化·包管理器
whale fall8 小时前
npm install安装的node_modules是什么
前端·npm·node.js
烛阴8 小时前
简单入门Python装饰器
前端·python
雪芽蓝域zzs8 小时前
uniapp 国密sm2加密
uni-app