在 Android 中获取 GPS 强度
在我的应用程序中,我必须找出 GPS 强度。但是,当我使用以下代码时,我仅得到 0 卫星数。所以,我无法获得 GPS 强度。
我的代码:
public void onCreate(Bundle savedInstanceState) {
locMgr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locMgr.addGpsStatusListener(onGpsStatusChange) ;
onGpsStatusChange.onGpsStatusChanged(GpsStatus.GPS_EVENT_SATELLITE_STATUS);
// Listener for GPS Status...
}
final Listener onGpsStatusChange=new GpsStatus.Listener()
{
public void onGpsStatusChanged(int event)
{
Log.e("gps","in class");
switch(event)
{
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
GpsStatus xGpsStatus =locMgr.getGpsStatus(null) ;
Iterable<GpsSatellite> iSatellites =xGpsStatus.getSatellites();
Iterator<GpsSatellite> it = iSatellites.iterator();
int count=0;
while(it.hasNext()){
count=count+1;
GpsSatellite oSat = (GpsSatellite) it.next();
Log.e("gps",""+oSat.getSnr());
}
Log.e("count",""+count);
tv1.setText(""+count);
break;
}
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以从 NMEA 句子中获取每个卫星的 GPS 信噪比
其中:
要收听 NMEA 数据,您需要创建一个 NMEA 监听器。
You can get GPS signal to noise ratio of each sat from the NMEA sentances
Where:
To listen to NMEA data you need to create a NMEA listener.
我发现获取(和过滤)准确性和修复位置的最佳方法是使用以下位置找到的解决方案:
http://developer.android.com/guide/ topic/location/obtaining-user-location.html#BestEstimate ,这是迄今为止我得到的最好结果。
假设您已经有了一个好的位置并且正在使用它(例如 animateTo ..)
然后假设您将该位置保存在 Location 变量中,并将其命名为
currentBestLocation
。您应该做的是将
isBetterLocation()
(来自“维护当前最佳估计”)我刚刚在您的活动中发布了 Google 网站向上)方法,然后在您的
onLocationChanged()
中发布您应该将
currentBestLocation
和刚刚从onLocationChanged()
获取的位置发送到isBetterLocation()
(例如,在
onLocationChanged()
中,您编写isBetterLocation(location, currentBestLocation)
。在
isBetterLocation()
中,它将向您发送回true< /code> 如果新位置比您现在拥有的最后一个位置更好(最后一个位置是
currentBestLocation
)如果它返回 true,则意味着准确性很好..您应该使用该位置
(不要忘记更新 -->
currentBestLocation = location
)I found that the best way to obtain (and filter) the accuracy and fix location is to use the solution found at:
http://developer.android.com/guide/topics/location/obtaining-user-location.html#BestEstimate , and that's the BEST result I got so far.
Suppose you already have a good location and you make use of it (e.g. animateTo ..)
then let's suppose you save that location in Location variable and you call it
currentBestLocation
.What you should do is put the
isBetterLocation()
(from "Maintaining a current best estimate"I just posted in google site upward) method in your activity, and then when in your
onLocationChanged()
you should send the
currentBestLocation
and the location you just got from theonLocationChanged()
toisBetterLocation()
(e.g. from
onLocationChanged()
you writeisBetterLocation(location, currentBestLocation)
.in
isBetterLocation()
it will send you backtrue
if the new location is better than the last location you have right now (the last location iscurrentBestLocation
)If it returns true, that means that the accuracy is good.. you should use that location
(don't forget to update -->
currentBestLocation = location
)好的,现在在 onLocationChanged() 中您应该添加以下内容:
OK, now in onLocationChanged() you should add the following: