0

你好,这是我用来获取纬度、经度和高度的代码。经度纬度得到正确但高度总是返回零。我不明白如何获取高度。请检查代码并告诉我。

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();
    }
4

2 回答 2

2

getAltitude()仅在hasAltitude()返回时调用false(当没有高度数据可用并因此0.0返回时)。

于 2015-03-04T16:00:11.747 回答
1

这取决于您手机上安装的 GPS 接收器。如果供应商在非标准 nmea 实现上实现某种排序,则可能并非所有信息都可用。您可以通过 sdk 检查芯片组是否支持高度。这里的文档

于 2014-05-19T09:35:32.717 回答