¿Cómo obtener información sobre los satélites de android?
Estoy tratando de obtener la información de satélite de la android y escribió este código siguiente que no está dando ningún resultado, podría cualquier punto de señalar por qué es así?
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); }
Gracias
Nohsib
De acuerdo con los documentos para LocationManager.getGpsStatus(...)
…
Esto sólo se debe llamar desde la devolución de llamada
onGpsStatusChanged(int)
para asegurarse de que los datos se copian atómicamente.
Intenta implementar GpsStatus.Listener
en tu actividad y reemplazando onGpsStatusChanged(int)
. Ejemplo…
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); } } }
Prueba esto:
LocationManager locmgr = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); //locmgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10L, 5.0f, this); Location location = locmgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if ( location == null ) { location = locmgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } if ( location == null ) { location = locmgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); }
Déjeme saber si cualquier problema.
He implementado este código (modificado, a continuación), pero todavía obtener obtener ningún desencadenamiento del evento onGpsStatusChanged. Modificación – a) no @Override – error causado ya que no hay método de superclase, yb) sustituido (int) por (int arg0) en
Public void onGpsStatusChanged (int)
Ya que obviamente es un error.