Android new location API Altitude is always zero

喜欢而已 提交于 2019-12-11 03:45:11

问题


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:


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.



来源:https://stackoverflow.com/questions/16894247/android-new-location-api-altitude-is-always-zero

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!