安卓 M Google API 客户端位置速度始终为 0,而 location.hasSpeed 为 false。

3

我正在使用谷歌API客户端进行位置更新,但它总是返回速度为0,而位置坐标则正常。我已在Motorola X2上测试了该应用程序。尽管在其他Android版本中表现良好。

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)

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

我遇到了完全相同的问题。我花了很长时间才发现问题所在。尝试打开谷歌地图以及您自己的应用程序,您会看到位置附带速度。我还没有找到解决方案。你找到了吗? - Lisandro
1个回答

0

我知道有点晚了,但对于仍然对解决方案感兴趣的人,这是我的方法。基本上,在每次位置更改时,我使用以下方法计算瞬时速度。由于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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接