【问题标题】:How to avoid repeat the same satellite information in list?如何避免列表中重复相同的卫星信息?
【发布时间】:2013-05-02 10:27:07
【问题描述】:

我创建了一个简单的应用程序来显示 GPS 传感器卫星信息。 信息显示为文本和列表永远不会停止更新相同的重复信息。 我如何保留独特的卫星信息?不要重复相同的信息。

public void onGpsStatusChanged() {

  GpsStatus gpsStatus = locationManager.getGpsStatus(null);
  if(gpsStatus != null) {
      Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
      Iterator<GpsSatellite>sat = satellites.iterator();
      int i=0;
      while (sat.hasNext()) {
          GpsSatellite satellite = sat.next();
           strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite:  "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n";
      }

      Satinfos.setText(strGpsStats);
  }
}

【问题讨论】:

    标签: android gps satellite


    【解决方案1】:

    我认为您的问题是您没有在每次调用 onGpsStatusChanged 之间清除您的 strGpsStats;虽然不确定,因为你的问题不是很清楚。试试这个:

    public void onGpsStatusChanged() {
      strGpsStats = "";
      GpsStatus gpsStatus = locationManager.getGpsStatus(null);
      if(gpsStatus != null) {
          Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
          Iterator<GpsSatellite>sat = satellites.iterator();
          int i=0;
          while (sat.hasNext()) {
              GpsSatellite satellite = sat.next();
               strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite:  "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n";
          }
    
          Satinfos.setText(strGpsStats);
      }
    }
    

    【讨论】:

      【解决方案2】:

      进入while后,需要检查重复信息。

          while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();
                  if(sat.Current != sat.next)
      {
                 strGpsStats+= (i++) + ": " + "Pseudo-random number for the satellite:  "+satellite.getPrn() + "," + "Satellite was used by the GPS calculation: " + satellite.usedInFix() + "," + "Signal to noise ratio for the satellite: "+satellite.getSnr() + "," + "Azimuth of the satellite in degrees: "+satellite.getAzimuth() + "," +"Elevation of the satellite in degrees: "+satellite.getElevation()+ "\n\n";
            }
      }
      

      【讨论】:

      • 也许需要数组?如果数据(i++)!=数据(i)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-19
      • 2019-02-26
      • 2014-01-07
      • 1970-01-01
      • 2013-02-26
      • 2018-05-27
      • 1970-01-01
      相关资源
      最近更新 更多