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

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

相关推荐
吴文周11 小时前
告别重复劳动:一套插件让 AI 替你写代码、修Bug、做测试、上生产
前端·后端·ai编程
Mh11 小时前
我决定写一个 3D 地球仪来记录下我要去的地方
前端·javascript·动效
yaoxin52112311 小时前
390. Java IO API - WatchDir 示例
java·前端·python
懒狗小前端11 小时前
做了一个 codex 的中文文档网站,做的不好可以随便喷
前端·后端
. . . . .12 小时前
ref、useRef 和 forwardRef
前端·javascript·react.js
energy_DT13 小时前
2026年海上钻井平台数字孪生平台:引领海洋能源数字化转型
前端
Eric_见嘉13 小时前
在职前端 Agent 配置分享
前端·后端·agent
柚子81613 小时前
break跳出语句块的神奇技巧
前端·javascript
ejinxian14 小时前
Rust GUI框架Azul与Electron、WebView2
前端·javascript·electron
IT_陈寒15 小时前
Vue的v-for里用index当key,我被自己坑惨了
前端·人工智能·后端