我可以在android中获得卫星名称吗?它显示我的SNR,PNR,仰角,方位角,但我不知道它显示的数据是否正确

时间:2011-10-03 15:14:11

标签: android

  package my.pack;

  import java.util.Iterator;

  import android.app.Activity;
  import android.content.Context;
  import android.location.GpsSatellite;
  import android.location.GpsStatus;
  import android.location.GpsStatus.NmeaListener;
  import android.location.Location;
  import android.location.LocationListener;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.Toast;

  public class SatellitesActivity extends Activity {
LocationManager locMgr;
double lat;
double lon;
  /** Called when the activity is first created. */
  @Override
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

     locMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     MyGpsListener listener = new MyGpsListener();
     MyLocationListener locListener = new MyLocationListener();
     locMgr.addGpsStatusListener(listener);      
     locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locListener);
     locMgr.addNmeaListener(new NmeaListener() {

        @Override
        public void onNmeaReceived(long timestamp, String nmea) {
            // TODO Auto-generated method stub
            Log.e("Test!", nmea);
        }
    });

   }



  public class MyGpsListener implements GpsStatus.Listener{
    @Override
    public void onGpsStatusChanged(int event) {
        // TODO Auto-generated method stub
        switch(event){
        case GpsStatus.GPS_EVENT_STARTED:Log.e("Started", "");
            break;
        case GpsStatus.GPS_EVENT_FIRST_FIX:Log.e("FirstFix", "");
            break;
        case GpsStatus.GPS_EVENT_STOPPED:Log.e("Sopped", "");
            break;
        case GpsStatus.GPS_EVENT_SATELLITE_STATUS:GpsStatus xGpsStatus = locMgr.getGpsStatus(null) ; 
        Iterable<GpsSatellite> iSatellites = xGpsStatus.getSatellites() ; 
        Iterator<GpsSatellite> it = iSatellites.iterator() ; 
        while ( it.hasNext() ) 
        { 
                GpsSatellite oSat = (GpsSatellite) it.next() ; 
                if(oSat.usedInFix()){
                    Log.e("A fost folosit ", "int fix!");
                }
                if(oSat.toString()!=null){

                    Log.e("Test", "SNR:"+oSat.getSnr()+"; Azimuth:"+oSat.getAzimuth()+"; Elevation:"+oSat.getElevation()+" "+oSat.toString()+"; PRN:"+oSat.getPrn());
                }
        } 
        break ; 


        }
    }
    }

public class MyLocationListener implements LocationListener{

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

        if(location!=null){
            lat = location.getLatitude();
            lon = location.getLongitude();
            Toast.makeText(getApplicationContext(), ""+lat+"\n"+lon, Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }}

}

2 个答案:

答案 0 :(得分:1)

卫星实际上没有你能抓住的名字。你能得到的最好的是PRN,你的代码已经告诉你了。

修改 经过一些阅读后,我发现有些人试图绘制PRN号码,即使有时这是不正确的。试试http://www.losangeles.af.mil/shared/media/document/AFD-070530-036.pdf

答案 1 :(得分:0)

您可以根据互联网上的某些参考(例如List of GPS satellites),使用您自己的代码将PRN号码映射到卫星名称。我不知道有任何类型的自动PRN解码服务将PRN号码解码为卫星名称。请注意,国防部可以在他们认为合适时自由地将PRN号码重新分配给不同的卫星。例如,如果USA-66明天死亡,他们很可能会(最终)将另一颗卫星重新分配给PRN 32。