Android new location API Altitude is always zero

2019-07-22 01:29发布

I am using Google new location Api in my app like this

private static final LocationRequest REQUEST = LocationRequest.create().setInterval(2000).setFastestInterval(1000)
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

private LocationListener mLocationListener = new LocationListener() {

    @Override
    public void onLocationChanged(final Location location) {
        if(location.hasAltitude()){
            Log.e(TAG, "Altitude " + location.getAltitude());
        }else{
            Log.e(TAG, "Location does not have altitude");
        }
    }
};

but location.hasAltitude() always false, I have tested it on real device and in open area, but it does not have altitude anywhere, but if I am using the old location Listener, its working fine,

1条回答
迷人小祖宗
2楼-- · 2019-07-22 01:51

As of 3.1.36 version of the API fused location provider always returns false there (at least for me when having GPS turned on), so you may want to stick with LocationManager and GPS provider.

Hopefully they will improve the fused algorithm in the future release.

查看更多
登录 后发表回答