Android的 - 地点从LocationClient了不支持的速度不支持、地点、速度、Android

2023-09-07 15:08:48 作者:看在眼里ゝ痛在心里

我是使用新的谷歌LocationClient获取地缘位置。而我需要的速度为每点(位置)。 我现在做的是:

 如果(mLocationClient == NULL){
    mLocationClient =新LocationClient(这一点,mLocationCallback,mLocationCallback);
    mLocationCallback.setLocationClient(mLocationClient);
    如果(!(mLocationClient.isConnected()|| mLocationClient.isConnecting())){
        mLocationClient.connect();
    }
}
 

在哪里mLocationCallback是一个实例

 公共类LocationCallback实现ConnectionCallbacks,
        OnConnectionFailedListener,LocationListener的{}
 

在功能,

  @覆盖
    公共无效onLocationChanged(位置定位){
        如果(位置== NULL){
            Log.e(TAG,onLocationChanged:位置==空);
            返回;
        }

        Log.i(TAG,位置@+ location.getLatitude()+,
                   + location.getLongitude()+,海拔高度:
                   + location.getAltitude()+(+ location.hasAltitude()
                   +)+速度:+ location.getSpeed​​()+米/秒(
                   + location.hasSpeed​​()+));
        }
}
 
Permissions Location android

不过,每次 location.hasSpeed​​()。看来,只有GPS提供商给速度。我敢肯定,我的GPS上,但它可能永远不会被使用。 有没有办法强制LocationClient使用GPS提供商?

解决方案   

有没有办法强制LocationClient使用GPS提供商?

没有,因为 LocationClient 的一点是,它混合来自多个源(GPS,WIFI,信号发射塔,传感器等)。数据

如果你需要速度,使用 LocationManager 并用 GPS_PROVIDER ,或其他任何的标准表示,支持速度(例如,伽利略,有一天,也许)。

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?

解决方案

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).