如何获取有关机器人的卫星的信息? [英] How to get information about the satellites from android?

查看:148
本文介绍了如何获取有关机器人的卫星的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图让从Android的卫星信息,并写了这以下的code这是不给任何结果,可能任何一个点,为什么会这样呢?


I am trying to get the satellite information from the android and wrote this following code which is not giving any results, could any one point out why is it so?

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gps);

    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    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++) + ": " + satellite.getPrn() + "," + satellite.usedInFix() + "," + satellite.getSnr() + "," + satellite.getAzimuth() + "," + satellite.getElevation()+ "\n\n";
         }
     }
     TextView tv = (TextView)(findViewById(R.id.Gpsinfo));
     tv.setText(strGpsStats);
}

感谢
Nohsib

thanks
Nohsib

推荐答案

根据文档的 LocationManager.getGpsStatus(...) ...

这应该只从 onGpsStatusChanged(INT)回调呼吁,以确保数据的原子复制。

This should only be called from the onGpsStatusChanged(int) callback to ensure that the data is copied atomically.

尝试实施 GpsStatus.Listener 您的活动并覆盖 onGpsStatusChanged(INT)。示例...

Try implementing GpsStatus.Listener on your Activity and overriding onGpsStatusChanged(int). Example...

public class MyActivity extends Activity implements GpsStatus.Listener {

    LocationManager locationManager = null;
    TextView tv = null;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gps);

        tv = (TextView)(findViewById(R.id.Gpsinfo));
        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();
            int i=0;
            while (sat.hasNext()) {
                GpsSatellite satellite = sat.next();
                strGpsStats+= (i++) + ": " + satellite.getPrn() + "," + satellite.usedInFix() + "," + satellite.getSnr() + "," + satellite.getAzimuth() + "," + satellite.getElevation()+ "\n\n";
            }
            tv.setText(strGpsStats);
        }
    }
}

这篇关于如何获取有关机器人的卫星的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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