Android:GPS - 视野中的几颗卫星,但没有用于修复

时间:2014-09-04 13:38:15

标签: android gps

有没有理由为什么有些卫星在视野中但没有一颗用于修复?

我制作了一个小应用程序来跟踪GPS位置,有时它会显示8个以上的卫星,但没有一个用于修复。

看看下面的图片。它说明了正在发生的事情:

enter image description here

每个“绿色箭头”指向设备所在的位置+方向。红线是我所说的“差距”。手机打开了,应用程序正在运行,位置管理员一直在接收“卫星状态更新”,但是在红线中它获得了0个“用于修复”的卫星。

这种情况发生在几种不同的设备型号(手机和平板电脑)和不同的Android版本(3.x到4.x)。

我想弄明白这一点。感谢任何帮助。

修改

一些相关代码:

@Override
public void onCreate()
{
    // when service is created, we start monitoring gps status 

    GpsStatus.Listener gpsStatusListener        = new GpsStatus.Listener()
    {

        @Override
        public void onGpsStatusChanged(int event)
        {
                LocationManager lm = (LocationManager) GooglePlayLocationServices.this.getSystemService(Context.LOCATION_SERVICE);
                GpsStatus gpsStatus = lm.getGpsStatus(null);
                String msg = "";

                if (event == GpsStatus.GPS_EVENT_STARTED)
                {
                        msg = "onGpsStatusChanged: " + "GPS_EVENT_STARTED";
                }
                else if (event == GpsStatus.GPS_EVENT_STOPPED)
                {
                        msg = "onGpsStatusChanged: " + "GPS_EVENT_STOPPED";
                }
                else if (event == GpsStatus.GPS_EVENT_FIRST_FIX)
                {
                        msg = "onGpsStatusChanged: " + "GPS_EVENT_FIRST_FIX";
                        msg += " = " + ((gpsStatus != null) ? gpsStatus.getTimeToFirstFix() / 1000 : 0) + "s";
                }
                else if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS)
                {
                        msg = "onGpsStatusChanged: " + "GPS_EVENT_SATELLITE_STATUS";
                        if (gpsStatus != null)
                        {
                                Iterable<GpsSatellite> satellites = gpsStatus.getSatellites();
                                Iterator<GpsSatellite> sat = satellites.iterator();
                                int i = 0;
                                int used = 0;
                                while (sat.hasNext())
                                {
                                        i++;
                                        GpsSatellite satellite = sat.next();
                                        if (satellite.usedInFix())
                                                used++;
                                }
                                msg += " - satelites = " + used + "/" + i;
                                lastSatelitesInfo = used + "/" + i;
                        }
                }
                if (msg.length() > 0)
                        log(msg);
        }

    };

    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    locationManager.addGpsStatusListener(gpsStatusListener);
)

日志输出:

[02/09/14 18:42:01] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:42:02] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:42:03] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
...
[02/09/14 18:44:23] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:44:24] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:44:25] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
...
[02/09/14 18:52:08] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:52:09] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 18:52:10] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
...
[02/09/14 19:56:32] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 19:56:33] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
[02/09/14 19:56:34] onGpsStatusChanged: GPS_EVENT_SATELLITE_STATUS - satelites = 0/11
...

1 个答案:

答案 0 :(得分:0)

在这些&#34;间隙期间,设备可能处于睡眠状态。 - 当您关闭屏幕时,设备进入休眠状态,应用程序不再能够访问CPU并且无法执行任何操作。

如果您想在跟踪期间确保设备处于唤醒状态,则需要获取PowerManager.WakeLock。假设这是你的方法:

PowerManager.WakeLock mWakelock;

public void doSomething() {
    mWakelock = ((PowerManager)getSystemService(Context.POWER_SERVICE))
                .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "wakelock_name");

    mWakelock.acquire();

    // Your long-running code

    mWakelock.release();
}

此外,如果您这样做,请不要忘记将android.permission.WAKE_LOCK权限添加到AndroidManifest.xml