0
votes

I am decided to see how the geo-positioning works in Qt. I'm using Qt 5.9.2.

I am create Qt Quick 2 application, and write in *.pro file:

QT += quick positioning

In main.qml file i am adding code:

import QtPositioning 5.4
...
    Text {
        id: labelLongitude

        anchors.left: parent.left
        anchors.top: parent.top

        font.pointSize: 24
    }

    Text {
        id: labelLatitude

        anchors.left: parent.left
        anchors.top: labelLongitude.bottom

        font.pointSize: 24
    }

    Text {
        id: labelSpeed

        anchors.left: parent.left
        anchors.top: labelLatitude.bottom

        font.pointSize: 24
    }

    Text {
        id: labelDirection

        anchors.left: parent.left
        anchors.top: labelSpeed.bottom

        font.pointSize: 24
    }

    Text {
        id: labelMagneticVariation

        anchors.left: parent.left
        anchors.top: labelDirection.bottom

        font.pointSize: 24
    }

    PositionSource {
        id: positionSource
        updateInterval: 1000
        active: true

        onPositionChanged: {
            var coord = positionSource.position.coordinate;
            console.log("Coordinate:", coord.longitude, coord.latitude);

            labelLongitude.text=qsTr("Longitude: ")+(coord.longitude);
            labelLatitude.text=qsTr("Longitude: ")+(coord.latitude);

            labelSpeed.text=qsTr("Speed: ")+positionSource.position.speed;
            labelDirection.text=qsTr("Direction: ")+positionSource.position.direction;
            labelMagneticVariation.text=qsTr("Magnetic Variation: ")+positionSource.position.magneticVariation;
        }
    }

And launched this application on the phone Honor 6 (H60-L04). As a result, latitude, longitude and speed are displayed normally.

But the direction and the magneticVariation - all the time show NaN, if i'm move or stand.

Question. How to fix the code so that these values are normally getting from the sensors?

1

1 Answers

0
votes

I figured it out.

The direction is work on the street with fast moving. If use application on the balcony, with 4 active satellite, the direction detect don't work.

Next, i'm incorrect translate Magnetic Variation. This sensor - is only for wery specified devices. I needed a magnetic bearing (in other words the geo azimuth). In PositionSource type the azimuth is not present. For get azimuth, must use the type Compass:

Compass {
    id: compass
    dataRate: 1
    active: true

    onReadingChanged: {
        labelAzimuth.text=qsTr("Azimuth: ")+compass.reading.azimuth;
    }
}