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

标签 android google-maps-api-3 gps location android-6.0-marshmallow

我正在使用 google api 客户端进行位置更新,它总是返回速度 0,但位置坐标即将到来。我已经在摩托罗拉 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)

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

最佳答案

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

关于Android M Google api 客户端位置速度始终为 0 和 location.hasSpeed false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34922070/

相关文章:

android - 在 BroadcastReceiver 中使用 IntentService 时如何传递上下文变量?

javascript - Google map api 绘制带有编码点的折线

android - SettingsApi 已弃用

java - 如何旋转 opengl 3d 对象以指向 GPS 位置(纬度、经度)?

android - 如何对 session 室数据进行分类?

android - Protocol Buffer 支持 byte[] 字段吗?

android - 如何在两台 PC 之间通过 USB 建立 adb 连接

javascript - Google Maps API 结果变量转换为 php

javascript - 使用自定义图标的 Angular 谷歌地图

Android开启/关闭定位的含义