I use the Location class to get altitude, but it always returns 0.
Please tell me how to get altitude?
Location.getAltitude();
Initially I used location.getAltitude() and it always retuned 0.0 . Then I came across https://groups.google.com/forum/#!topic/android-beginners/KNeLh905ip0 it helped me solve my problem. It works on actual real device.
private LocationProvider _locationProvider;
private LocationManager _locationManager;
_locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
_locationProvider = _locationManager
.getProvider(LocationManager.GPS_PROVIDER);
location = _locationManager.getLastKnownLocation
(LocationManager.GPS_PROVIDER);
_locationProvider.supportsAltitude();
hasaltitude = location.hasAltitude();
double altitude = location.getAltitude();
System.out.println("HasAltitude" + hasaltitude+"-"+altitude);
The value of "altitude" is will be in meters.
Altitude is typically only available with GPS provider. You can check with available location provider if the support altitude:
locationProvider.hasAltitude();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With