孙肖宁

React Native获取当前的位置信息
引入依赖包import Geolocation from 'Geolocation';调用方法//获取经纬度的方法...
扫描右侧二维码阅读全文
23
2018/11

React Native获取当前的位置信息

  1. 引入依赖包

    import Geolocation from 'Geolocation';
  2. 调用方法

    //获取经纬度的方法 
       getLongitudeAndLatitude = () => {
           //获取位置
           return new Promise(() => {
    
               Geolocation.getCurrentPosition(
                   location => {
                       //可以获取到的数据
                       var result = "速度:" + location.coords.speed +
                           "\n经度:" + location.coords.longitude +
                           "\n纬度:" + location.coords.latitude +
                           "\n准确度:" + location.coords.accuracy +
                           "\n行进方向:" + location.coords.heading +
                           "\n海拔:" + location.coords.altitude +
                           "\n海拔准确度:" + location.coords.altitudeAccuracy +
                           "\n时间戳:" + location.timestamp;
                       console.log(result);
                   },
                   error => {
                       console.log("失败")
                   }
               );
           })
       }
Last modification:November 28th, 2018 at 05:21 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment