【问题标题】:Cannot get satellite count Android无法获取卫星计数 Android
【发布时间】:2011-03-04 18:32:21
【问题描述】:

通过 adb 使用 geo fix 命令时,我似乎无法获取卫星计数。

地理修复帮助内容如下:

geo fix <longitude> <latitude> [<altitude> [<satellites>]]
allows you to send a simple GPS fix to the emulated system
The parameters are:

<longitude>   longitude, in decimal degrees
<latitude>    latitude, in decimal degrees
<altitude>    optional altitude in meters
<satellites>  number of satellites being tracked (1-12)

我使用如下命令设置地理位置触发 OnLocationChanged 执行:

geo fix -106.1221 52.1311 514 5

在 OnlocationChanged 中:

Location newestloc = loc; 
Bundle sats = newestloc.getExtras();
int satcount = 0;
satcount = sats.getInt("satellites");

但是,每当我调用 satcount 时,我总是得到 0。通过地理定位的卫星数量是否不计算在内?

还有其他方法可以获取手机 GPS 当前看到的卫星数量吗?

编辑: 我也尝试过以下代码:

GpsStatus gpsstat = mlocManager.getGpsStatus(null);
Iterable sats = gpsstat.getSatellites();
Iterator satI = sats.iterator();
        int count = 0;
        while(satI.hasNext()){
            GpsSatellite gpssatellite = (GpsSatellite) satI.next();
            if (gpssatellite.usedInFix()){
            count++;
            }
        }

每次我得到修复时,这应该至少返回 1,但它永远不会从 0 改变。

【问题讨论】:

    标签: java android gps


    【解决方案1】:

    http://developer.android.com/reference/android/location/GpsStatus.html

    试试 getSatellites()

    您测试的是什么类型的手机? 您是否尝试过检查 lbstest 模式返回的内容?可能是手机本身没有接收到任何卫星。

    【讨论】:

    • 我也试过了。 int count = 0;for (Iterator &lt;GpsSatellite&gt; sats = (Iterator&lt;GpsSatellite&gt;) mlocManager.getGpsStatus(null).getSatellites();sats.hasNext();){count++;sats.next();}satcount = count;以上也不起作用,仍然返回0。
    • 我正在使用三星 Galaxy S 进行测试。但这是一个旁注,因为我提到我正在尝试使用 adb 完成计数。我的意思是它也会转移到手机上,但如果应用程序在 adb 中接收到它,它应该转移到手机上。该应用程序正在运行,因为它会拾取 GPS 修复并将其显示在屏幕上(经过测试),但它不会显示它检测到的卫星数量。
    • 我会在 adb 日志中寻找什么?我一直在使用 adb logcat 来捕获代码中的错误,因此我知道在哪里修复它们,但是当我从另一个命令窗口使用 geo fix 命令时,我没有在日志中看到任何更改。
    【解决方案2】:

    在某些版本中,Android 对 geo fix 命令的处理似乎存在错误。您可能想尝试geo fix -106.1221 52.1311 514 5 12,其中数字 5 在某些实现中被忽略,而 12 被视为卫星的数量。 所以有缺陷的系统上的实际语法是

    geo fix <longitude> <latitude> [<altitude> [<dummy> <satellites>]]
    

    【讨论】:

      【解决方案3】:

      由于我无法找到相关信息,并且该应用似乎在没有卫星数量的情况下运行良好,因为这只是我们正在查看的一个额外字段。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多