Code snippet that draws ui and shows GPS data and accuracy, also with GPS on/off switch if one wants to conserve power.
// Made by: Ossipena
This is done with PageStack so you need main.qml that defines pagestackwindow and MainPage.qml that is loaded
within the pagestack (here appWindow)
main.qml:
import QtQuick 1.1
import com.nokia.meego 1.0
PageStackWindow {
id: appWindow
MainPage {id: mainPage}
ToolBarLayout {
id: commonTools
visible: true
TabButton {
text: "View trackings"
height: parent.height
width: 400
onClicked: appWindow.pageStack.push(Qt.resolvedUrl("ViewPage.qml"))
}
ToolIcon { platformIconId: "toolbar-view-menu";
onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
}
}
}
MainPage.qml:
import QtQuick 1.1
import com.meego 1.0
import Qt 4.7
import QtMobility.location 1.1
Page {
id: mainPage
tools: commonTools
//init GPS etc
PositionSource {
id: positionSource
updateInterval: 1000
//active: false
active: gpsswitch.checked
}
function printableMethod(method) {
if (method == PositionSource.SatellitePositioningMethod)
return "Satellite";
else if (method == PositionSource.NoPositioningMethod)
return "Not available";
else if (method == PositionSouce.NonSatellitePositioningMethod)
return "Non-satellite";
else if (method == PositionSource.AllPositioningMethods)
return "All/multiple"
return "source error";
}
Grid {
id: positiondata
anchors.top: parent.top
anchors.topMargin: 50
anchors.left: parent.left
anchors.leftMargin: 10
columns: 2
spacing: 5
//visible: false
Text {
id:latitudelabel
font.pointSize: 32
text: "Latitude:"
}
Text {
id: latitudetext
font.pointSize: 32
text: positionSource.position.coordinate.latitude
}
Text {
id:longitudelabel
font.pointSize: 32
text: "Longitude: "
}
Text {
id: longitudetext
font.pointSize: 32
text: positionSource.position.coordinate.longitude
}
Text{
id:accuracylabel1
font.pointSize: 16
text: "Horizontal accuracy:"
}
Text{
id: horiz_accuracy
font.pointSize: 16
text: positionSource.position.horizontalAccuracy
}
Text {
id:heightlabel
font.pointSize: 32
text: "Height: "
}
Text {
id: heighttext
font.pointSize: 32
text: positionSource.position.coordinate.altitude
}
Text{
id:accuracylabel2
font.pointSize: 16
text: "Altitude accuracy:"
}
Text{
id: vert_accuracy
font.pointSize: 16
text: positionSource.position.verticalAccuracy
}
}
Row {
id: switchrow
width: 300
spacing: 10
anchors.top: positiondata.bottom
anchors.left: positiondata.left
anchors.topMargin: 50
// Switch for power saving: toggle gps on/off
Text {
id:switchtext
anchors.left: parent.left
font.pointSize: 32
text: gpsswitch.checked ? "GPS ON" : "GPS OFF"
}
Switch {
id: gpsswitch
checked: false
anchors.left: switchtext.right
anchors.leftMargin: 50
}
}
}