问题描述
我如何检查GPS接收器的现状如何?我已经检查了 LocationListener的
<$c$c>onStatusChanged方法,但不知何故,似乎不工作,或者只是错误的可能性。
How can I check the current status of the GPS receiver? I already checked the LocationListener
onStatusChanged
method but somehow it seems that is not working, or just the wrong possibility.
基本上,我只需要知道,如果在屏幕顶部的GPS图标闪烁(无实际修复)或固体(修补程序可)。
Basically I just need to know if the GPS icon at the top of the screen is blinking (no actual fix) or solid (fix is available).
推荐答案
首先,我的SpeedView,一个GPS测速仪为Android的开发者,所以你可以相信我,当我说,我们想尽一切可能的解决方案此问题,都具有相同的阴性结果。让我们开始重申什么行不通:
First of all, I'm a developer of SpeedView, a GPS speedometer for Android, so you can trust me when I say that we tried every possible solution to this problem, all with the same negative result. Let's start by reiterating what doesn't work:
- onStatusChanged()不会被调用的埃克莱尔和升级Froyo。它被调用的1.6虽然。
- 在简单计算,当然所有可用的卫星的,没用的。
- 检查是否有任何卫星的usedInFix返回true()是不是也很有帮助。该系统显然失去了修复,但仍继续报告,但是也有一些在以前的几个SATS。
所以,唯一可行的解决方案,我们有,而且一个我们实际上在我们的应用程序中使用,如下。比方说,我们有这样一个实现了GpsStatus.Listener简单的类:
So, the only working solution we have, and the one we actually use in our application, is the following. Let's say we have this simple class that implements the GpsStatus.Listener:
private class MyGPSListener implements GpsStatus.Listener {
public void onGpsStatusChanged(int event) {
switch (event) {
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
if (mLastLocation != null)
isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;
if (isGPSFix) { // A fix has been acquired.
// Do something.
} else { // The fix has been lost.
// Do something.
}
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
// Do something.
isGPSFix = true;
break;
}
}
}
好了,现在在onLocationChanged(),你应该添加以下内容:
OK, now in onLocationChanged() you should add the following:
@Override
public void onLocationChanged(Location location) {
if (location == null) return;
mLastLocationMillis = SystemClock.elapsedRealtime();
// Do something.
mLastLocation = location;
}
就是这样。基本上,这是它所有的行:
And that's it. Basically, this is the line that does it all:
isGPSFix = (SystemClock.elapsedRealtime() - mLastLocationMillis) < 3000;
您可以调整课程的毫秒数,但我会建议设置它周围3-5秒。
You can tweak the milliseconds value of course, but I would suggest to set it around 3-5 seconds.
这实际工作,虽然我还没有看到源$ C $ C,它实现了标准的GPS图标,这是接近复制其行为。它甚至可以超越它大声笑。希望这可以帮助别人。
This actually works and though I haven't seen the source code that implements the standard GPS icon, this comes close to replicating its behavior. It could even outdo it lol. Hope this helps someone.
这篇关于如何检查GPS接收器的现状如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!