在没有活动的情况下使用 Google 地图位置

时间:2023-03-22
本文介绍了在没有活动的情况下使用 Google 地图位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一项服务,它通过注册 LocationManager.requestLocationUpdates 来接收位置.但是有些手机出现了一些问题.

I have a service which receives locations through registering a LocationManager.requestLocationUpdates. But there have been some issues on some phones.

当电池电量不足时,网络位置提供程序会停止发送位置修复(此问题已在 这个 SO 问题).这不仅是我的应用程序的问题,而且其他应用程序也只是停止接收位置.即使手机已充电,问题仍然存在,直到完全重新启动.

When battery runs low, the network location provider stops sending location fixes (this problem is addressed in this SO question). It's not a only a problem with my app but also the other apps just stop receiving locations. Even when the phone is recharged the problem persists until the full reboot.

但是,我发现(并且有人在上面的 SO 问题中也提到过)Google 地图仍然不断接收位置更新 - 当我打开 Google 地图应用时,它会显示正确的位置和更新.

However, I found out (and someone also mentioned it in the SO question above) that Google Maps still keeps receiving location updates - when I open Google Maps app it shows the correct location and updates.

所以我正在考虑使用 Google Maps API 中的位置的解决方法.我完全没有使用 Maps API 的经验,但它似乎需要一个适当的 GUI (Activity) 应用程序才能使用.还是我错了?是否有可能使用 Google Maps API 甚至在服务内接收位置?

So I was thinking about a workaround of using locations from Google Maps API. I have absolutely no experience with the Maps API, but it seems that it needs a proper GUI (Activity) application to be used with. Or am I wrong? Is there a possibility to use Google Maps API to receive locations even within the Service?

推荐答案

鉴于可靠来源的一些广泛测试,我相信您可能需要考虑使用 Google Play 服务提供的 FusedLocationProvider.选择合适的功率标准等似乎让您头疼.

Given some extensive testing from a reliable source, I believe that you might want to consider using the FusedLocationProvider supplied with Google Play Services. It seems to take the headache out of choosing the appropriate power criteria and so on.

请注意,这将要求用户必须在其设备上安装 Google Play,因此 Kindle 等设备将无法使用.它还需要至少 Android 2.2.

Be aware that this will require that the user must have Google Play installed on their device, so Kindles and the like will be out of the picture. It also requires a minimum of Android 2.2.

有关 Google Play 服务提供的定位服务的更多信息,请参阅这里.

Some more information about the location services provided by Google Play Services can be found here.

这篇关于在没有活动的情况下使用 Google 地图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:网络位置提供商不提供位置 android 下一篇:使用 json 获取当前位置

相关文章