Android的定位API:获取提供程序状态 [英] Android Location API: Get Provider Status

查看:142
本文介绍了Android的定位API:获取提供程序状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Android中获得一个位置提供的状态的最好方法?当报考位置更新一个LocationListener的,在 onStatusChanged(字符串提供商,INT地位,捆绑演员)每当状态更改回调将被调用。不过,我并没有获取的当前状态(可用 OUT_OF_SERVICE TEMPORARILY_UNAVAILABLE )没有注册到位置更新。在 isProviderEnabled 方法只是表明如果提供的是一般开启或没有(在设备的设置),所以可能会返回真正虽然提供者暂停服务...是否有这样做的另一种方式?

What is the best way in Android to get a location provider's status? When registering a LocationListener for location updates, the onStatusChanged(String provider, int status, Bundle extras) callback will be called whenever the status is changed. However, I didn't find a way for getting the current status (AVAILABLE, OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE) without registering to location updates. The isProviderEnabled method just indicates if the provider is generally turned on or not (in the device's settings), so might return true although the provider is out of service... Is there another way for doing this?

另一个问题:是否有可能侦听状态更新而无需位置更新注册?我要听一个特定的供应商的位置,但在同一时间检查,如果别人得到使用。我目前的解决方法是设置最小的时间和距离,以一个非常高的价值,但我不知道是否有更好的解决方案...

Another question: is it possible to listen for status updates without registering for location updates? I want to listen on a specific provider for locations, but at the same time check if others get available. My current workaround is to set the minimum time and distance to a very high value, but I wonder if there's a better solution...

感谢您的任何提示!

BTW:如果可能的话,解决方案应与Android 1.1的工作

Btw: if possible, the solutions should work with Android 1.1

推荐答案

为什么要GPS状态,如果你不感兴趣的地区?

Why do you want the GPS status, if you are not interested in the location?

不过,你可以得到的GPS状态至少某些方面是这样的:

However, you can get at least some aspects of the GPS status like this:

final GpsStatus gs = this.locationManager.getGpsStatus(null);
int i = 0;
final Iterator<GpsSatellite> it = gs.getSatellites().iterator();
while( it.hasNext() ) {
    it.next();
    i += 1;
}
this.gpsSatsAvailable = i;

请参阅 http://developer.android.com/reference/android/location /GpsStatus.html
您将需要一个3D修复(包括海拔)至少4颗卫星的准确2D修复和5。
根据该文件,你应该从访问onStatusChanged()的状态,以获得一致的信息。它的工作原理也是从这个方法之外。链接的文档说明,可能会出现什么问题。
当然,你仍然需要监听位置更新,因为GPS状态不更新,否则。

See http://developer.android.com/reference/android/location/GpsStatus.html You will need at least 4 satellites for an accurate 2D fix, and 5 for a 3D fix (incl. altitude). According to the documentation you should access the status from onStatusChanged() to get consistent information. It works also from outside this method. The linked document explains what problems may occur. Of course, you still need to listen for location updates, because the GPS status is not updated otherwise.

这篇关于Android的定位API:获取提供程序状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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