在Android中通过GPS获取位置时如何获取卫星名称或编号?编号、位置、名称、Android

2023-09-07 10:17:16 作者:寒笙

我是 android 新手,我通过 gps 获取位置,我也在代码中获取卫星编号,但我想获取用于获取位置的特定卫星名称或编号.我有很多谷歌,但没有得到适当的解决方案.

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.

我的问题是:-1.是否可以获得特定的卫星名称或编号?如果是,请帮助我如何找到它?

提前致谢

推荐答案

locationManager.getGpsStatus(null).getSatellites()(调用者可以传入一个GpsStatus对象来设置最新的状态信息,或者传入null来创建一个新的GpsStatus对象.)

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.)

返回代表当前状态的 GpsSatellite 对象数组GPS 引擎.

Returns an array of GpsSatellite objects, which represent the current state of the GPS engine.

locationManager.getGpsStatus(null).getSatellite().getPrn()返回卫星的 PRN(伪随机数).

locationManager.getGpsStatus(null).getSatellites().getPrn() Returns the PRN (pseudo-random number) for the satellite.

getMaxSatellites()返回 getSatellites() 可以返回的卫星列表中的最大卫星数.

getMaxSatellites () Returns the maximum number of satellites that can be in the satellite list that can be returned by getSatellites().

代码:

  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()+ "

";

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