简体   繁体   English

融合位置GPS在打开Goog​​le地图之前不会更新

[英]Fused Location GPS doesn't update until opening Google Maps

I'm using fused location provider in my app which is set to PRIORITY_HIGH_ACCURACY at an interval of 60 seconds. 我在我的应用程序中使用融合位置提供程序,以60秒的间隔设置为PRIORITY_HIGH_ACCURACY This usually works but sometimes the location doesn't update for 5 to 10 minutes by itself, and I when I open Google Maps, it seems to trigger a location update. 这通常有效,但有时位置本身不会更新5到10分钟,而当我打开谷歌地图时,它似乎会触发位置更新。

Anyone else here who might have run into this issue or knows of the possible causes behind this behavior? 这里的任何其他人可能遇到过这个问题,或者知道这种行为背后的可能原因? Is there any way to fix this? 有没有什么办法解决这一问题?

Gps does not always return a location even it's available through FusedLocationProvider api or LocationManager LocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) . Gps并不总是返回一个位置,即使它可以通过FusedLocationProvider api或LocationManager LocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) Especially, if you are indoors it's less likely to get location from Gps depending on your device's Gps chip. 特别是,如果你在室内,根据你设备的Gps芯片,不太可能从Gps获得位置。 Gps must be fixed to return a location. 必须修复Gps才能返回位置。

You can write a test app which has LocationManager with Gps, Wifi and GpsStatusListener to check satellite count, satellites in the fix, and satellite signal strength and compare it with FusedLocationProvider at the same time and add the locations provided to map as markers. 您可以编写一个测试应用程序,其中包含带有Gps,Wifi和GpsStatusListener的LocationManager,以检查卫星计数,修复中的卫星和卫星信号强度,并同时将其与FusedLocationProvider进行比较,并将提供的位置添加到地图中作为标记。 You can also look for Location.getExtras() for FLP which may contain info about satellites. 您还可以查找FLP的Location.getExtras() ,其中可能包含有关卫星的信息。 Even if LocationManager Gps is available and satellite count is 2 i can not get a location from Gps. 即使LocationManager Gps可用且卫星计数为2,我也无法从Gps获取位置。

Hello World in image should be Gps location but it's not returned since it's not fixed yet. 图像中的Hello World应该是Gps位置,但由于尚未修复,因此未返回。 LocationManager Gps状态测试 Testing may not solve your problem but you can compare situations you get location or you can not for example it may required to use 3 satellites to get location from Gps or minimum signal strength. 测试可能无法解决您的问题,但您可以比较您获得位置的情况,或者您不能比较它可能需要使用3颗卫星从Gps获取位置或最小信号强度。 It may also take too long for Gps to lock and status on GpsStatusListener is set to GpsStatus.GPS_EVENT_FIRST_FIX when it's locked. Gps锁定并且GpsStatusListener上的状态在锁定时设置为GpsStatus.GPS_EVENT_FIRST_FIX也可能需要很长时间。 It took about 5 minutes for me Gps to get fixed and return a location. 我需要大约5分钟Gps来修复并返回一个位置。 I also wrote another test with maps and i had the same issue until Gps is fixed on both LocationManager and FLP. 我还用地图编写了另一个测试,直到Gps在LocationManager和FLP上修复之前我都有同样的问题。

My findings from the following link the Fused Location Provider will only maintain background location if at least one client is connected to it. 我从以下链接中发现的融合位置提供程序仅在至少有一个客户端连接到它时才会保留后台位置。 Once the first client connects, it will immediately try to get a location. 一旦第一个客户端连接,它将立即尝试获取位置。 If your activity is the first client to connect and you call getLastLocation() right away in onConnected() , that might not be enough time for the first location to come in. This will result in the location being null . 如果您的活动是第一个连接的客户端,并且您在onConnected()立即调用getLastLocation() ,则第一个位置可能没有足够的时间进入。这将导致该位置为null

To solve this issue, you have to wait (indeterminately) till the provider gets the location and then call getLastLocation() , which is impossible to know. 要解决此问题,您必须等待(不确定),直到提供程序获取位置,然后调用getLastLocation() ,这是不可能知道的。

Another (better) option is to implement the com.google.android.gms.location.LocationListener interface to receive periodic location updates (and switch it off once you get the first update). 另一个(更好)选项是实现com.google.android.gms.location.LocationListener接口以接收定期位置更新(并在获得第一次更新后将其关闭)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM