在Android中通过GPS获取位置时如何获取卫星名称或编号? [英] how to get satellite name or number when we are getting location through GPS in Android?

查看:50
本文介绍了在Android中通过GPS获取位置时如何获取卫星名称或编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 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);
            }
        }
    }
}

这篇关于在Android中通过GPS获取位置时如何获取卫星名称或编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆