PDA

View Full Version : گرفتن تعداد ماهواره در GPS



ali_khodayar
چهارشنبه 02 تیر 1395, 12:04 عصر
با سلام خدمت دوستان .

کسی میدونه که چطور میشه تعداد ماهواره در زمان برقراری ارتباط با GPS رو گرفت؟

این کد رو اکثر سایت ها گفتن که استفاده کردن و جواب گرفتن . اما جواب نمیده



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);
Toast.makeText(getApplicationContext(), strGpsStats, 100).show();
}
}

در قسمت While شرط هیچوقت بر قرار نیست و وارد نمیشه
لطفأ راهنمایی کنید.
ممنونم .

rezaricky
پنج شنبه 03 تیر 1395, 13:45 عصر
سلام .
شما باید برای این کار یک listener ثبت کنی .
این تکه کد رو تست کنید :
locationManager.addGpsStatusListener(new GpsStatus.Listener() { @Override
public void onGpsStatusChanged(int event) {
int satellites = 0;
int satellitesInFix = 0;
int timetofix = locationManager.getGpsStatus(null).getTimeToFirstF ix();
Log.i(TAG, "Time to first fix = " + timetofix);
for (GpsSatellite sat : locationManager.getGpsStatus(null).getSatellites() ) {
if (sat.usedInFix()) {
satellitesInFix++;
}
satellites++;
}
Log.i(TAG, satellites + " Used In Last Fix (" + satellitesInFix + ")");
}
});

ali_khodayar
یک شنبه 06 تیر 1395, 13:37 عصر
با تشکر از شما دوست عزیز.
بله درسته باید Listener اضافه کنم. مشکل من هم همین بود و رفع شد.