0

I am testing my app on emulator with a gpx file. Coordinates change, but bearing and speed are always zero. I've checked my LocationManager settings, and both .supportsSpeed() and .supportsBearing() return true.

My GPS code is almost one-to-one with this one http://www.androidhive.info/2012/07/android-gps-location-manager-tutorial/ but this part is most important so I paste it here:

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;
}

I've only added this code

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

I instantiate GPSTracker object in activity's onCreate method, and then use gps.getLocation() where needed.

My .gpx file used for testing is available here: http://snk.to/f-cdzj45ic

wojciech_rak
  • 2,276
  • 2
  • 21
  • 30
  • do you have checked your gpx file? Does it contain speed and bearing. Does the simulator support speed and bearing from gpx. are the gpx tags to be used for the simulator related to speed and bearing, described? – AlexWien May 29 '13 at 12:05

1 Answers1

1

Tried it on a physical device, and worked well. I just thought that gpx with list of waypoints is enough, and bearing and speed will be calculated from it.

wojciech_rak
  • 2,276
  • 2
  • 21
  • 30