hello,this is my code that I am used to get latitude,longitude and altitude.Longitude latitude getting properly but altitude return always zero.I could not understand how to get altitude.please check code and let me know.
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
if(!location.hasAltitude())
{
altitude=location.getAltitude();
}else
{
altitude=1.0;
}
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
if(!location.hasAltitude())
{
altitude=location.getAltitude();
}else
{
altitude=1.0;
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
that depends of the gps receiver installed on your phone. If the vendor implements some sort on not standard nmea implementation, is possible that not all the information are available. You can check if the chipset does support altitude through the sdk. Here the documentation