Search code examples
androidgpslocationlocation-clientlocation-services

Android LocationServices getLastLocation returns speed as 0


It gets connected, I can get the latitude and the longitude of the coordinate, but when I do the following code, speed = 0, why can't it take the speed from the location?

 @Override
public void onLocationChanged(final Location location) {

    Log.i("","geof is s onLocationChanged ENTERED");
    if (LocationServices.FusedLocationApi.getLastLocation(mLocationClient) != null) {

         locEnd = location;
         Log.i("","geof is s speed of locend:" + location.getSpeed());
    }
}

This will always be my response:

03-31 17:43:57.227  31463-31463/nl.hgrams.passenger I/﹕ geof is s speed of locend:0.0

And this are my permissions:

   <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.LOCATION_HARDWARE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="nl.hgrams.passenger.C2D_MESSAGE" />

Solution

  • I'm not sure if this is what you're looking for: https://developer.android.com/reference/android/location/Location.html#getSpeed()

    But it's "normal" for getSpeed to return 0.0 to you as a default because your location does not have speed (as showed in the documentation).