UNI-APP 离线状态下 获取设备的经纬度以及速度等

UNI-APP 离线状态下 获取设备的经纬度以及速度等

uni-app 写的一个app在无网络情况下,也可以通过设备的gps定位芯片,做到及时获取自生的经度 、纬度、速度等数据值

话不多说直接上代码

<template>
	<view>
		<button type="default" @click="getLocation_1">点击获取当前位置</button>
		<view class="ani">
			获取位置次数 {{count}}---设备打开飞行模式,打开gps定位功能  就可以在没有网络的情况下获取 经纬度和速度了
		</view>
		<view class="box_location">
			经度:{{location_J}}
		</view>
		<view class="box_location">
			纬度:{{location_w}}
		</view>
		<view class="box_speed">
			速度:{{speed}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				location_J:"",
				location_w:"",
				speed:"",
				count:0,
				res_t:''
			}
		},
		methods: {
			getLocation_1(){
				console.log(88888888888)
				var that=this;
					console.log("开始获取位置")
					uni.getLocation({
					    type: 'wgs84',
					    success: function (res) {
							that.res_t=res
							console.log(res.latitude)
							that.location_J=res.longitude;
							that.location_w=res.latitude;
							that.speed=res.speed;
							}
					});
				}
			}
	}
	
</script>

<style>

</style>

注意事项就一条

  • 设备具有GPS定位芯片

  • 设备的gps定位功能一定要开启,(因为这个不开无法定位,找了一小天)

    ctrl +c ctrl+v 运行起来

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值