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

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

相关推荐
椒盐螺丝钉35 分钟前
Vue Router应用:组件跳转
前端·javascript·vue.js
顾安r38 分钟前
11.20 开源APP
服务器·前端·javascript·python·css3
敲敲了个代码1 小时前
CSS 像素≠物理像素:0.5px 效果的核心密码是什么?
前端·javascript·css·学习·面试
少云清2 小时前
【软件测试】5_基础知识 _CSS
前端·css·tensorflow
倔强青铜三2 小时前
AI编程革命:React + shadcn/ui 将终结前端框架之战
前端·人工智能·ai编程
天外飞雨道沧桑2 小时前
前端开发 Cursor MCP 提效工具配置
前端·vscode·ai编程·开发工具·cursor
朱哈哈O_o2 小时前
前端通用包的作用——jquery篇
前端
葡萄城技术团队2 小时前
纯前端驱动:在线 Excel 工具的技术革新与实践方案
前端·excel
芳草萋萋鹦鹉洲哦2 小时前
【vue】调用同页面其他组件方法几种新思路
前端·javascript·vue.js
且白3 小时前
uniapp离线打包问题汇总
uni-app