How To Get Satellite Name Or Number When We Are Getting Location Through Gps In Android?
I am new in android, I am getting location through gps, I am also getting satellite number in our code but I want to get specific satellite name or number which is used to get the
Solution 1:
locationManager.getGpsStatus(null).getSatellites() (The caller may either pass in a GpsStatus object to set with the latest status information, or pass null to create a new GpsStatus object.)
Returns an array of GpsSatellite objects, which represent the current state of the GPS engine.
locationManager.getGpsStatus(null).getSatellites().getPrn() Returns the PRN (pseudo-random number) for the satellite.
getMaxSatellites () Returns the maximum number of satellites that can be in the satellite list that can be returned by getSatellites().
Code :
publicclassSatellitesInfoActivityextendsActivityimplementsGpsStatus.Listener {
LocationManagerlocationManager=null;
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.addGpsStatusListener(this);
}
@OverridepublicvoidonGpsStatusChanged(int) {
GpsStatusgpsStatus= locationManager.getGpsStatus(null);
if(gpsStatus != null) {
Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
Iterator<GpsSatellite>sat = satellites.iterator();
StringlSatellites=null;
inti=0;
while (sat.hasNext()) {
GpsSatellitesatellite= sat.next();
lSatellites = "Satellite" + (i++) + ": "
+ satellite.getPrn() + ","
+ satellite.usedInFix() + ","
+ satellite.getSnr() + ","
+ satellite.getAzimuth() + ","
+ satellite.getElevation()+ "\n\n";
Log.d("SATELLITE",lSatellites);
}
}
}
}
Solution 2:
publicclassSatellitesInfoActivityextendsActivityimplementsGpsStatus.Listener {
LocationManagerlocationManager=null;
publicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.addGpsStatusListener(this);
}
@OverridepublicvoidonGpsStatusChanged(int event) {
GpsStatusgpsStatus= locationManager.getGpsStatus(null);
if(gpsStatus != null) {
Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
Iterator<GpsSatellite>sat = satellites.iterator();
StringlSatellites=null;
inti=0;
while (sat.hasNext()) {
GpsSatellitesatellite= sat.next();
lSatellites = "Satellite" + (i++) + ": "
+ satellite.getPrn() + ","
+ satellite.usedInFix() + ","
+ satellite.getSnr() + ","
+ satellite.getAzimuth() + ","
+ satellite.getElevation()+ "\n\n";
Log.d("SATELLITE",lSatellites);
}
}
}
}
Post a Comment for "How To Get Satellite Name Or Number When We Are Getting Location Through Gps In Android?"