how to get satellite name or number when we are ge

2020-05-29 03:31发布

问题:

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 location. I have google so much but not getting proper solution regarding this.

My Question is:- 1. It is possible to get a particular satellite name or number ? if yes please help me how to find it ?

Thanks in advance

回答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 :

  public class SatellitesInfoActivity extends Activity implements GpsStatus.Listener {

    LocationManager locationManager = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylayout);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.addGpsStatusListener(this);
    }

    @Override
    public void onGpsStatusChanged(int) {
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        if(gpsStatus != null) {
            Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
            Iterator<GpsSatellite>sat = satellites.iterator();
            String lSatellites = null;
            int i = 0;
            while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();
                lSatellites = "Satellite" + (i++) + ": " 
                     + satellite.getPrn() + "," 
                     + satellite.usedInFix() + "," 
                     + satellite.getSnr() + "," 
                     + satellite.getAzimuth() + "," 
                     + satellite.getElevation()+ "\n\n";

                Log.d("SATELLITE",lSatellites);
            }
        }
    }
}


回答2:

public class SatellitesInfoActivity extends Activity implements GpsStatus.Listener {

    LocationManager locationManager = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylayout);
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        locationManager.addGpsStatusListener(this);
    }

    @Override
    public void onGpsStatusChanged(int event) {
        GpsStatus gpsStatus = locationManager.getGpsStatus(null);
        if(gpsStatus != null) {
            Iterable<GpsSatellite>satellites = gpsStatus.getSatellites();
            Iterator<GpsSatellite>sat = satellites.iterator();
            String lSatellites = null;
            int i = 0;
            while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();
                lSatellites = "Satellite" + (i++) + ": " 
                 + satellite.getPrn() + "," 
                 + satellite.usedInFix() + "," 
                 + satellite.getSnr() + "," 
                 + satellite.getAzimuth() + "," 
                 + satellite.getElevation()+ "\n\n";

                Log.d("SATELLITE",lSatellites);
            }
        }
    }
}