问题
I'm using the new Google LocationClient to retrieve geo locations. And I need to get speed for each point (location).
What I'm doing now is:
if (mLocationClient == null) {
mLocationClient = new LocationClient(this, mLocationCallback, mLocationCallback);
mLocationCallback.setLocationClient(mLocationClient);
if (!(mLocationClient.isConnected() || mLocationClient.isConnecting())) {
mLocationClient.connect();
}
}
Where mLocationCallback is an instance of
public class LocationCallback implements ConnectionCallbacks,
OnConnectionFailedListener, LocationListener {}
In the function,
@Override
public void onLocationChanged(Location location) {
if (location == null) {
Log.e(TAG, "onLocationChanged: location == null");
return;
}
Log.i(TAG, "Location@ " + location.getLatitude() + ","
+ location.getLongitude() + ", Altitude: "
+ location.getAltitude() + "(" + location.hasAltitude()
+ ")" + " Velocity: " + location.getSpeed() + " m/s("
+ location.hasSpeed() + ")");
}
}
However, everytime location.hasSpeed()
gives false
. It seems that only GPS provider gives speed. I'm sure my GPS is on but it might never be used.
Is there a way to force LocationClient to use GPS provider?
回答1:
Is there a way to force LocationClient to use GPS provider?
No, because the point of LocationClient
is for it to blend data from multiple sources (GPS, WiFi, cell towers, sensors, etc.).
If you need speed, use LocationManager
and work with the GPS_PROVIDER
, or anything else the Criteria
says supports speed (e.g., Galileo, someday, maybe).
来源:https://stackoverflow.com/questions/17239006/android-locations-got-from-locationclient-doesnt-support-speed