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

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

相关推荐
donecoding1 分钟前
前端AI开发:为什么选择SSE,它与分块传输编码有何不同?axios能处理SSE吗?
前端·人工智能
安_6 分钟前
<style scoped>跟<style>有什么区别
前端·vue
姝然_95277 分钟前
Claude Code 命令完整文档
前端
wjcroom7 分钟前
web版进销存的设计到实现一
前端
无知的前端10 分钟前
Flutter常见问题以及解决方案
前端·flutter·dart
BD_Marathon22 分钟前
Vue3_Vite构建工程化前端项目
前端
武清伯MVP24 分钟前
CSS Grid布局全解析:从基础到实战的二维布局方案
前端·css·grid
xfq29 分钟前
typescript泛型枚举以及NaN传染处理
前端·typescript
ErMao29 分钟前
开始搭建第一个React项目吧~
前端·react.js
Yanni4Night39 分钟前
JavaScript打包器大奖赛:谁是构建速度之王? 🚀
前端·javascript