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 28, 2018
If you think my article is useful to you, please feel free to appreciate