Created
February 27, 2017 19:17
-
-
Save shakil807g/5cc6ce3a9ce2e7a7dab3ad6c4e2a2cc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://stackoverflow.com/questions/4811920/why-getspeed-always-return-0-on-android?rq=1 | |
new LocationListener() { | |
private Location mLastLocation; | |
@Override | |
public void onLocationChanged(Location pCurrentLocation) { | |
//calcul manually speed | |
double speed = 0; | |
if (this.mLastLocation != null) | |
speed = Math.sqrt( | |
Math.pow(pCurrentLocation.getLongitude() - mLastLocation.getLongitude(), 2) | |
+ Math.pow(pCurrentLocation.getLatitude() - mLastLocation.getLatitude(), 2) | |
) / (pCurrentLocation.getTime() - this.mLastLocation.getTime()); | |
//if there is speed from location | |
if (pCurrentLocation.hasSpeed()) | |
//get location speed | |
speed = pCurrentLocation.getSpeed(); | |
this.mLastLocation = pCurrentLocation; | |
//////////// | |
//DO WHAT YOU WANT WITH speed VARIABLE | |
//////////// | |
} | |
@Override | |
public void onStatusChanged(String s, int i, Bundle bundle) { | |
} | |
@Override | |
public void onProviderEnabled(String s) { | |
} | |
@Override | |
public void onProviderDisabled(String s) { | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment