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?