LocationAvailability没有可用的位置 [英] LocationAvailability No Location Available

查看:204
本文介绍了LocationAvailability没有可用的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google的Android的 FusedLocationProviderApi 在过去几个月内已被弃用, FusedLocationProviderClient 是其继任者,所以我最近更新了客户端应用中使用的location API,以使用新的.

Google's FusedLocationProviderApi for Android was recently deprecated within the past few months, with FusedLocationProviderClient being its successor so I recently updated the location APIs used in my client's app to use the new ones.

每次在 LocationCallback 中触发 onLocationAvailability 时,当 locationAvailability.isLocationAvailable()返回 false 时,我会通知用户,但是在某些设备上,这种情况似乎比我预期的发生得更多.我在前台 Service 中运行这些位置更新,而这些位置更新保持一致至关重要.有没有办法确定这种失败的原因,如此

Every time onLocationAvailability is fired in LocationCallback I notify the user when locationAvailability.isLocationAvailable() returns false, but it appears that this condition occurs more often than I expected on some devices. I run these location updates inside a foreground Service and it is crucial that these location updates remain consistent. Is there a way to determine the cause of this failure so

  1. 我们不会向最终用户表明任何误报
  2. 我们可以尝试解决问题,或者至少向最终用户报告他们应该怎么做?

在我看来,已弃用的API可以对这些问题提供更多的见解,因为它是与 GoogleApiClient 结合使用的,或者我可能缺少一些更小的细节.

It appears to me that either the deprecated APIs provide more insight into these issues since it was used in conjunction with GoogleApiClient or perhaps I'm missing some smaller details.

推荐答案

onLocationAvailability ,当位置数据的可用性.何时isLocationAvailable()返回假,您可以假定不会返回该位置onLocationResult(LocationResult),直到设备的设置或环境.即使isLocationAvailable()返回true,onLocationResult(LocationResult)可能并不总是定期调用,但是设备位置已知并且最近传送的位置和getLastLocation(GoogleApiClient)鉴于活动者指定的提示,将合理更新LocationRequests.

onLocationAvailability Called when there is a change in the availability of location data. When isLocationAvailable() returns false you can assume that location will not be returned in onLocationResult(LocationResult) until something changes in the device's settings or environment. Even when isLocationAvailable() returns true the onLocationResult(LocationResult) may not always be called regularly, however the device location is known and both the most recently delivered location and getLastLocation(GoogleApiClient) will be reasonably up to date given the hints specified by the active LocationRequests.

因此,此方法不提供有关原因的信息.

So this method does not provide information about reason.

  1. 我们不会向最终用户表明任何误报

  1. We don't indicate any false positives to the end-user

  • 当前,我只是忽略此方法的结果,因为它经常返回false,然后再次返回true,依此类推.

我们可以尝试解决问题,或者至少向最终用户报告他们应该怎么做?

We can try to fix the issue or at least report to the end-user what they should do?

检查您是否拥有权限,并在需要时请求它们(文档)

Check if you have permissions, request them if needed (docs)

这篇关于LocationAvailability没有可用的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆