The return value from the getAltitude() method always returns 0.00. Many answers suggest it could be down to the provider not supporting altitude details. I have checked this and it does support altitude.
I want to obtain the altitude from GPS coordinates. Any help is appreciated.
My code can been seen below.
LocationManager locationManager; LocationProvider locationProvider;
/* Get LocationManager and LocationProvider for GPS */
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationProvider = locationManager.getProvider(LocationManager.GPS_PROVIDER);
/* Check if GPS LocationProvider supports altitude */
Location l = new Location("A");
As far as I know, a Location will only have an altitude when triangulated by the GPS itself, using the satellites as points of reference. When you get the Location from the provider, it does that to calculate altitude, but when you force specific coordinates you don't get that.
To know the height of a specific coordinate (different from the current GPS coordinate), you should query that info from a map (ex: bing3d or openstreetmap).
You are manually assembling a Location object. If you wish for that Location object to return a non-zero value for getAltitude(), you need to call setAltitude().
If you wish to get device's current location, possibly including its altitude, you can use LocationManager, as is covered in the documentation.
If you are trying to get the elevation above sea level of the surface of the Earth at a particular latitude and longitude, Android does not have anything for that. You will need to find some sort of library or Web service that has those details.
Asked in February 2016Viewed 1,281 timesVoted 5Answered 3 times