GeoFlickr (QML)

This is a small example, illustrating one of the very core parts of the Qt Positioning API: the ability to retrieve and use the user's current geographic position.

Key QML types shown in this example:

Image non disponible

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 the Current Position

Retrieving the user's current position is achieved using the PositionSource type. In this example, we instantiate the PositionSource as part of the GeoTab component (the floating "window" describing current position and status).

 
Sélectionnez
    PositionSource {
        id: positionSource
        onPositionChanged: { planet.source = "images/sun.png"; }

        onSourceErrorChanged: {
            if (sourceError == PositionSource.NoError)
                return

            console.log("Source error: " + sourceError)
            activityText.fadeOut = true
            stop()
        }

        onUpdateTimeout: {
            activityText.fadeOut = true
        }
    }

When the "Locate and update" button is pressed, we first interrogate the PositionSource to check if it has an available backend for positioning data. If it does not, we fall back to using a pre-recorded NMEA log for demonstration. We then instruct the PositionSource to update.

 
Sélectionnez
    Button {
        id: locateButton
        text: "Locate & update"
        onClicked: {
            if (positionSource.supportedPositioningMethods ===
                    PositionSource.NoPositioningMethods) {
                positionSource.nmeaSource = "nmealog.txt";
                sourceText.text = "(filesource): " + printableMethod(positionSource.supportedPositioningMethods);
            }
            positionSource.update();
        }
    }

To share the new position data with the rest of the application, we use properties that we have created on the GeoTab component:

 
Sélectionnez
    property variant coordinate

Using the Current Position

The longitude and latitude values retrieved here are eventually set on in propert