问题
How do my android
cellphone get the a driving car speed from GPS?
Can you give me an example which it can get car location from GPS and get speed?
Any advice is a help. Thank you very much.
回答1:
The location has an attribute speed which you get by getSpeed() method.
The GPS receiver chip determines speed NOT by distance and time relation. It uses the Doppler Shift Effect, which gives more precise speed. The higher the speed, the more acurate it is. Under 10km/h it does not work well.
回答2:
// Acquire a reference to the system Location Manager
LocationManager locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
location.getLatitude();
Toast.makeText(context, "Current speed:" + location.getSpeed(),
Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, locationListener);
}
回答3:
Using android locationmanager you can get latest last known location and in Location class getSpeed() method is there which will gve speed
the speed if it is available, in meters/second over ground.
If this location does not have a speed then 0.0 is returned.
Another way is find the distance between two location using location manager & provider and Location has one method to get distance in meter distanceTo(Location)
Convert Distance to meter and get the time From Location Class using getTime() and apply speed formula (speed = distance/time)
来源:https://stackoverflow.com/questions/28044261/android-gps-get-driving-car-speed