你好,這是我的代碼,我用來獲取緯度,經度和海拔高度。緯度得到正確,但海拔回報總是零。我不明白如何獲得altitude.please檢查代碼並讓我知道。海拔高度一直通過GPS android
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();
}
你是否在屋頂下獲得緯度爲零的長度? – Dhrupal
是的..但經緯度越來越完美..但高度總是爲零 – user3651987