Getting satellite information

Sometimes your app needs more than just the position of a user's device. Your app might also need to know the position of the satellites in use. You can use the QGeoSatelliteInfoSource and QGeoSatelliteInfo classes to find information about the satellites that are available and get updates on their positions. You can get information about where the satellites are located relative to a device's location by initializing the QGeoSatelliteInfoSource.

QGeoSatelliteInfoSource *satSrc = 
    QGeoSatelliteInfoSource::createDefaultSource(this);

You can request a single update to get satellite information using requestUpdate(). Or, you can request multiple updates using startUpdates() and stopUpdates().

There are two signals that are useful: satellitesInViewUpdated() and satellitesInUseUpdated(). Both of these signals return a list of satellites as a list of QGeoSatelliteInfo objects. The difference is that the satellitesInViewUpdated() signal returns the list of satellites that are in view of your device but not necessarily used by your device. Sometimes satellites can be too close to each other or they may have very weak signal strength. These conditions make it more difficult to compute the location. In these conditions, data from some satellites is discarded while computing the location fix. The satellitesInUseUpdated() signal is useful for retrieving the list of satellites that are actually in use by your device. Here's a code sample that initializes the QGeoSatelliteInfoSource, connects slots to the satellitesInViewUpdated() and satellitesInUseUpdated() signals, and gets a single fix for the satellites.

//Set up the satellite info source.
QGeoSatelliteInfoSource *satSrc = 
    QGeoSatelliteInfoSource::createDefaultSource(this);

// Connect the satellitesInUseUpdated() signal to a slot
// that handles satellites in use.

bool inUseSlotConnected = connect(satSrc, 
   SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)),
   this, 
   SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &)));

if (inUseSlotConnected) {
    // satellitesInUseUpdated() SIGNAL connected. 
} else {
    // satellitesInUseUpdated() SIGNAL failed to connect.
    // This is not normal in most cases and can be
    // a critical situation for your app! Make sure
    // you know exactly why this has happened. Add 
    // some code to recover from the lost connection 
    // below this line.
 
}

// Connect the satellitesInViewUpdated() signal to a slot
// that handles satellites in view.

bool inViewSlotConnected = connect(satSrc, 
   SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)),
   this, 
   SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &)));

if (inViewSlotConnected) {
    // satellitesInViewUpdated() SIGNAL connected. 
} else {
    // satellitesInViewUpdated() SIGNAL failed to connect.
    // This is not normal in most cases and can be
    // a critical situation for your app! Make sure
    // you know exactly why this has happened. Add 
    // some code to recover from the lost connection 
    // below this line.
   
}

// Get the position of the satellites available and in use.
satSrc->requestUpdate();

When your app receives one of the two signals indicating that satellite information has been received, it will get a list of QGeoSatelliteInfo objects. Each QGeoSatelliteInfo object contains the following information:

  • Elevation: The elevation of the satellite, in degrees.
  • Azimuth: The angle between the north point and the perpendicular projection of the satellite down onto the horizon, in degrees.
  • prnNumber: The pseudo random noise number (PRN) used to correlate relative timing measurements from several satellites (and the known positions of the satellites) to determine a satellite's position.
  • signalStrength: The strength of the satellite's signal.

Last modified: 2013-12-21

comments powered by Disqus