当前位置:asp编程网>技术教程>MUI教程>  正文

uni获取当前所在地理位置和GPS相关信息

2020-01-25 15:47:15   来源:网络   作者:佚名   浏览量:2119   收藏
<template>
<view>
<view>{{location}}</view>
</view>
</template>
<script>
export default {
onReady() {
this.showgps();
},
data(){
return{
location:''
}
},
methods:{
showgps(){
uni.getLocation({
  // 默认为 wgs84 返回 gps 坐标,
  // gcj02 返回国测局坐标,可用于 uni.openLocation 的坐标
  type: 'wgs84',
  geocode: true,
  success: (data) => {
    if (data.address){
      this.location = data;
    }
  },
  fail: (err) => {
    console.log(err)
    // this.$api.msg('获取定位失败');
  }
});
}
}
}

</script>

这段代码就可以获取当前手机所在的地理位置和GPS相关信息,需要在手机上才能看到效果。


关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网