IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

SatelliteInfo (QML)

The SatelliteInfo example shows the available satellites using Sky View or RSSI View and the user's current position. The satellites currently contributing to the GPS fix are marked as pink.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

SatelliteInfo (QML)

This example demonstrates the usage of Qt Positioning QML API:

The example shows satellite information in two different tabs. The data is taken from the SatelliteSource::satellitesInView and SatelliteSource::satellitesInUse properties.

Image non disponible

The Sky View tab shows the relative satellite positions using the Azimuth and Elevation attributes.

Image non disponible

The RSSI View tab shows the signal strength of satellites in view using the signalStrength property.

In both cases, the displayed numbers are the individual satellite identifiers. The satellites that are currently used to calculate the GPS fix are marked pink.

The Current Position block below the satellite information uses PositionSource::position property to show the current latitude and longitude.

The Status block shows the current mode or the last error.

The application operates in three different modes:

Application mode

Description

Running

The application continuously queries the system for satellite and position updates. When new data is available it will be displayed.

Stopped

The application stops updating the satellite and position information.

Single

The application makes a single satellite and position update request.

The application automatically switches into a simulation mode if the platform does not provide satellite or position information. The simulation mode uses an NMEA plugin with pre-recorded NMEA data.

Apple does not provide any APIs to retrieve satellite information, so on macOS and iOS the satellite information will always be taken from pre-recorded data. These API limitations do not affect positioning information, so current position can be displayed correctly.

Running the Example

To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.

Retrieving Current Position

The current position is retrieved from the PositionSource QML object. The onPositionChanged handler is used to receive position updates. The string representations of latitude and longitude are extracted from the coordinate property.

 
Sélectionnez
PositionSource {
    id: positionSource
    name: root.simulation ? "nmea" : ""
    onPositionChanged: {
        let posData = position.coordinate.toString().split(", ")
        positionAndStatus.latitudeString = posData[0]
        positionAndStatus.longitudeString = posData[1]
    }
}

Retrieving Satellite Information

Similarly to the position, the current satellite information is retrieved from the SatelliteSource QML object. The onSatellitesInViewChanged and onSatellitesInUseChanged handlers are used to get the updated satellites in view and satellites in use respectively. The data is then combined into a single model, which is passed to both Sky View and RSSI View tabs.

 
Sélectionnez
SatelliteSource {
    id: satelliteSource
    name: root.simulation ? "nmea" : ""
    onSatellitesInViewChanged: root.updateModel()
    onSatellitesInUseChanged: {
        root.inUseIds.clear()
        for (var i = 0; i < satellitesInUse.length; ++i)
            root.inUseIds.add(satellitesInUse[i].satelliteIdentifier)

        root.updateModel()
    }
}

QML Module Registration

 

CMake Build

For a CMake-based build, we need to add the following to the CMakeLists.txt:

 
Sélectionnez
qt_add_qml_module(satelliteinfo
    URI SatelliteInformation
    VERSION 1.0
    QML_FILES
        Button.qml
        Main.qml
        RssiView.qml
        PositionAndStatus.qml
        SkyView.qml
        ViewSwitch.qml
)

qmake Build

For a qmake build, we need to modify the satelliteinfo.pro file in the following way:

 
Sélectionnez
qml_resources.files = \
    qmldir \
    Button.qml \
    Main.qml \
    RssiView.qml \
    PositionAndStatus.qml \
    SkyView.qml \
    ViewSwitch.qml

qml_resources.prefix = /qt/qml/SatelliteInformation

RESOURCES += qml_resources

Example project

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+