0

在我的应用程序中,我必须找出 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;
                            }
                    }
            };
4

3 回答 3

2

您可以从 NMEA 句子中获得每个卫星的 GPS 信噪比

 $GPGSV,2,1,08,01,40,083,46,02,17,308,41,12,07,344,39,14,22,228,45*75

在哪里:

      GSV          Satellites in view
      2            Number of sentences for full data
      1            sentence 1 of 2
      08           Number of satellites in view

      01           Satellite PRN number
      40           Elevation, degrees
      083          Azimuth, degrees
      46           SNR - higher is better
           for up to 4 satellites per sentence
      *75          the checksum data, always begins with *

要收听 NMEA 数据,您需要创建NMEA 侦听器。

于 2011-05-31T13:06:36.060 回答
2

我发现获得(和过滤)准确度和修复位置的最佳方法是使用在以下位置找到的解决方案:http: //developer.android.com/guide/topics/location/obtaining-user-location.html#BestEstimate,这是迄今为止我得到的最好的结果。

假设您已经有一个好的位置并且您使用它(例如 animateTo ..),那么假设您将该位置保存在 Location 变量中并调用它currentBestLocation

你应该做的是把isBetterLocation()(来自我刚刚在谷歌网站上发布的“维护当前最佳估计”)方法放在你的活动中,然后在你的活动中,onLocationChanged() 你应该发送currentBestLocation你刚刚从onLocationChanged()到的位置isBetterLocation() (例如从onLocationChanged()你写isBetterLocation(location, currentBestLocation)

如果新位置比您现在拥有的最后一个位置更好(最后一个位置是),isBetterLocation()它会将您送回truecurrentBestLocation

如果它返回 true,则表示准确性很好。您应该使用该位置(不要忘记更新 --> currentBestLocation = location

于 2011-12-09T15:10:38.097 回答
0
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() 你应该添加以下内容:

@Override
public void onLocationChanged(Location location) {
    if (location == null) return;
    mLastLocationMillis = SystemClock.elapsedRealtime();
    // Do something.
    mLastLocation = location;
}
于 2011-05-31T12:16:31.740 回答