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>