首页 > 解决方案 > Android 仅在 90 秒后尝试获取位置

问题描述

我在我们正在开发的自定义 Android 设备上遇到了一些 GPS/位置问题。一般来说,GPS 很快,但我在启动后第一次请求位置时,大约需要 90 秒才能得到修复。我首先认为这是 AGPS 的问题,但它似乎工作正常。

这是 logcat 的摘录。我在 15:37:02 启动了一个请求 GPS 的应用程序。没有发生太多事情,几乎正好 90 秒后,我得到了很多活动。

我添加了一些此处不可见的进一步调试语句,似乎正在发生的事情是仅在 90 秒后,Android 尝试通过 NTP 获取时间,然后尝试执行 AGPS,并在几秒钟内得到修复。请注意,此设备当前未插入 SIM 卡。有谁知道什么会导致这种行为?我认为 Android 等待的原因是,出于省电的原因,它会在 GPS 之前首先尝试其他位置来源,但这对我来说无关紧要,因为该设备不是电池供电的。

# logcat | grep -Ei '(gps|locatio)'
...
02-21 15:36:49.362  2555  4381 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.chartcross.gpstest/.GPSTest (has extras)} from uid 10009 on display 0
02-21 15:36:49.436  2555  2763 I ActivityManager: Start proc 5898:com.chartcross.gpstest/u0a27 for activity com.chartcross.gpstest/.GPSTest
...
02-21 15:37:00.806  4736  5100 I GCoreUlr: Starting service, intent=Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) }, extras=Bundle[{receiverAction=init, is_boot=true}]
02-21 15:37:00.976  4736  5126 I GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction com.google.android.location.internal.server.ACTION_RESTARTED
02-21 15:37:01.260  4736  5126 I GCoreUlr: WorldUpdater:com.google.android.location.internal.server.ACTION_RESTARTED: Ensuring that reporting is stopped because of reasons: (no Google accounts)
02-21 15:37:01.904  4736  5126 I GCoreUlr: WorldUpdater received intent Intent { act=com.google.android.location.reporting.ACTION_UPDATE_WORLD cmp=com.google.android.gms/com.google.android.location.reporting.service.DispatchingService (has extras) } with receiverAction init
02-21 15:37:02.661  2555  4381 I ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.chartcross.gpstest/.GPSTest (has extras)} from uid 10009 on display 0
02-21 15:37:02.714  2555  6671 I ActivityManager: Start proc 7164:com.chartcross.gpstest/u0a27 for activity com.chartcross.gpstest/.GPSTest
...
02-21 15:38:32.349  2555  2838 D GpsLocationProvider: received SIM related action:
02-21 15:38:32.356  2555  2838 D GpsLocationProvider: SIM MCC/MNC is still not available
02-21 15:38:32.356  2555  2838 D GpsLocationProvider: received SIM related action:
02-21 15:38:32.361  2555  2838 D GpsLocationProvider: SIM MCC/MNC is still not available
02-21 15:38:32.689  2555  2838 D GpsLocationProvider: receive broadcast intent, action: android.intent.action.SIM_STATE_CHANGED
02-21 15:38:32.689  2555  2838 D GpsLocationProvider: received SIM related action:
02-21 15:38:32.698  2555  2838 D GpsLocationProvider: SIM MCC/MNC is still not available
02-21 15:38:32.699  2555  2838 D GpsLocationProvider: receive broadcast intent, action: android.intent.action.SIM_STATE_CHANGED
02-21 15:38:32.699  2555  2838 D GpsLocationProvider: received SIM related action:
02-21 15:38:32.704  2555  2838 D GpsLocationProvider: SIM MCC/MNC is still not available
02-21 15:38:32.704  2555  2838 D GpsLocationProvider: received SIM related action:
02-21 15:38:32.709  2555  2838 D GpsLocationProvider: SIM MCC/MNC is still not available
02-21 15:38:35.207  2555  2838 D GpsLocationProvider: setRequest ProviderRequest[ON interval=0]
02-21 15:38:35.214  2555  2838 D GpsLocationProvider: startNavigating, singleShot is false
02-21 15:38:35.214  2555  2838 D GpsLocationProvider: setting position_mode to standalone
02-21 15:38:35.214  2555  2838 V GpsLocationProvider: reportStatus status: 1
02-21 15:38:35.215  2555  2838 D GpsLocationProvider: setRequest ProviderRequest[OFF]
02-21 15:38:35.216  2555  2838 D GpsLocationProvider: stopNavigating
02-21 15:38:35.216  2555  2838 V GpsLocationProvider: reportStatus status: 2
02-21 15:38:35.218  2555  2838 D GpsLocationProvider: receive broadcast intent, action: android.net.conn.CONNECTIVITY_CHANGE
02-21 15:38:35.223  2555  2838 D GpsLocationProvider: setRequest ProviderRequest[ON interval=0]
02-21 15:38:35.223  2555  2838 D GpsLocationProvider: startNavigating, singleShot is false
02-21 15:38:35.223  2555  2838 D GpsLocationProvider: setting position_mode to standalone
02-21 15:38:35.223  2555  2838 V GpsLocationProvider: reportStatus status: 1
02-21 15:38:35.237  2555  4243 D MARTIAN_ANDROID: 142.496 ZS location_cb
02-21 15:38:35.238  2555  4243 V GpsLocationProvider: reportLocation lat: XXXXXX long: XXXXXX timestamp: 1550759917000
02-21 15:38:35.238  2555  4243 D GpsLocationProvider: TTFF: 14

标签: androidgpsandroid-source

解决方案


推荐阅读