0

我创建了一个简单的应用程序来显示 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);
  }
}
4

2 回答 2

1

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

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);
  }
}
于 2013-05-02T11:06:27.907 回答
0

进入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";
      }
}
于 2013-05-02T10:38:05.463 回答