海拔高度始终为0.我无法获得海拔高度

And*_*eaF 3 android altitude

我的高度始终为0.我想在Android中使用GPS获取海拔高度.

我的代码是:

public void onLocationChanged(Location location) {
    double lat = (double) (location.getLatitude());
    double lng = (double) (location.getLongitude());
    double alt = (double) (location.getAltitude());
    latitudine = (int) (lat * 1e6);
    longitudine = (int) (lng * 1e6);
    altitudine = (int) (alt * 1e6);
}
Run Code Online (Sandbox Code Playgroud)

Nip*_*pey 5

您是否检查过这是否是特定于设备的?你在模拟器中工作吗?

我首先检查一下,如果您的设备支持高度确定,请执行以下操作:

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 */
locationProvider.supportsAltitude();
Run Code Online (Sandbox Code Playgroud)

如果您想知道某个位置是否设置了有效高度,请使用以下命令:

Location location;

/* Get current location from GPS */
location = Location(LocationManager.GPS_PROVIDER);

/* Check if the requested Location has its altitude set */
location.hasAltitude();
Run Code Online (Sandbox Code Playgroud)