Android - Locations got from LocationClient doesn't support speed

旧街凉风 提交于 2019-12-02 03:16:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!