我为显示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);
}
}
答案 0 :(得分: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);
}
}
答案 1 :(得分:0)
进入时,需要检查重复信息。
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";
}
}