Android GPS轴承和速度始终为零

时间:2013-05-29 10:04:22

标签: android gps location ddms

我正在使用gpx文件在模拟器上测试我的应用程序。 坐标变化,但轴承和速度始终为零。 我检查了我的LocationManager设置,.supportsSpeed()和.supportsBearing()都返回true。

我的GPS代码与此http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/几乎是一对一的,但这一部分是最重要的,所以我将其粘贴在此处:

public Location getLocation() {
    try {
        locationManager = (LocationManager) mContext
                .getSystemService(LOCATION_SERVICE);


        isGPSEnabled = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);


        isNetworkEnabled = locationManager
                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

        if (!isGPSEnabled && !isNetworkEnabled) {

        } 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 (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) {
                        Log.d("GPS support",((Boolean)locationManager.getProvider(locationManager.GPS_PROVIDER).supportsBearing()).toString());
                        Log.d("GPS support",((Boolean)locationManager.getProvider(locationManager.GPS_PROVIDER).supportsSpeed()).toString());
                        location = locationManager
                                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return location;
}

我只添加了此代码

@Override
public void onLocationChanged(Location location) {
    this.location = location;
}

我在activity的onCreate方法中实例化GPSTracker对象,然后在需要时使用gps.getLocation()。

用于测试的.gpx文件可在此处找到:http://snk.to/f-cdzj45ic

1 个答案:

答案 0 :(得分:0)

在物理设备上尝试过,效果很好。 我只是认为带有航点列表的gpx足够了,轴承和速度将从中计算出来。