Android M Google api 客户端位置速度始终为 0,location.hasSpeed false



我正在使用谷歌 api 客户端进行位置更新,它总是返回速度 0,但位置坐标即将到来。我已经在摩托罗拉 X2 中测试了该应用程序。尽管它在其他安卓版本中运行良好。

LocationRequest request = LocationRequest.create(); request.setPriority(Thresholds.PRIORITY_HIGH); // request.setInterval(GlobalData.GPS_INTERVAL); request.setFastestInterval(GlobalData.GPS_INTERVAL); LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, request, this)

任何帮助将不胜感激:)。

我知道

有点晚了,但对于仍然对这里的解决方案感兴趣的人来说,这是我的。基本上在每个位置更改中,我都使用以下方法计算瞬时速度。由于GPS波动,它不是100%准确的,但这是一个开始。基本上你需要计算图形的斜率,所以你必须取两个点y1和y2,它们是两个不同时间点x1和x2中的两个不同位置。瞬时速度由公式 dy/dx 得出,其中 dy = y2-y1 和 dx = x2 -x1

private double calculateInstantaneousSpeed(Location location) {

    double insSpeed = 0;
    if (y1 == null && x1 <= -1) {
        //mark the location y1 at time x1
        y1 = location;
        x1 = duration.getDurationAsSeconds();

    } else {
        //mark the location y2 at time x2
        y2 = location;
        x2 = duration.getDurationAsSeconds();

        //calculate the slope of the curve (instantaneous speed)
        dy = y1.distanceTo(y2);
        dx = x2 - x1;
        insSpeed = dy / dx;
        y1 = y2;
        x1 = x2;
    }
    Singleton.getInstance().instantaneousSpeedSamples.add(insSpeed);
    //System.out.println("Instantaneous Speed m/s: "+insSpeed);
    return insSpeed;
}

最新更新