uniApp获取实时定位

通过你获取的key放到项目manifest.json里面,对应填写你所需要的key值,还有高德用户名

用户名:

key值的位置:

代码:

html:

<view class="intList pdNone">
	<view class="label">详细地址</view>
	<uni-easyinput @iconClick="goLocalAddress" placeholder="请点击图标获取详细地址" v-model="form.address" />
</view>

js:

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值