【问题标题】:Getting GPS strength in Android在 Android 中获取 GPS 强度
【发布时间】:2011-09-05 10:42:17
【问题描述】:

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

【问题讨论】:

    标签: android android-location


    【解决方案1】:

    您可以从 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 listener

    【讨论】:

      【解决方案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() 中,如果新位置比您现在拥有的最后一个位置更好(最后一个位置是currentBestLocation),它会将true 发回给您

      如果返回 true,则表示准确度很好。您应该使用该位置 (别忘了更新——>currentBestLocation = location

      【讨论】:

      • 这个答案似乎与问题无关
      【解决方案3】:
      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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-30
        相关资源
        最近更新 更多