Meego Wiki
Views

QML/Get GPS data

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
(removed extra braces)
Line 1: Line 1:
Code snippet that draws ui and shows GPS data and accuracy, also with GPS on/off switch if one wants to conserve power.
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
 +
* Modified by: Venemo
 +
 +
== main.qml ==
<pre>
<pre>
-
// 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 QtQuick 1.1
import com.nokia.meego 1.0
import com.nokia.meego 1.0
Line 14: Line 11:
PageStackWindow {
PageStackWindow {
     id: appWindow
     id: appWindow
 +
    initialPage: mainPage
-
     MainPage {id: mainPage}
+
     MainPage {
-
 
+
        id: mainPage
-
 
+
    }
-
 
+
     ToolBarLayout {
     ToolBarLayout {
         id: commonTools
         id: commonTools
         visible: true
         visible: true
 +
        parent: appWindow.pageStack.currentPage
-
 
+
         Button {
-
         TabButton {
+
             text: "View trackings"
             text: "View trackings"
             height: parent.height
             height: parent.height
-
            width: 400
 
-
            onClicked: appWindow.pageStack.push(Qt.resolvedUrl("ViewPage.qml"))
 
-
 
         }
         }
-
 
+
         ToolIcon {
-
         ToolIcon { platformIconId: "toolbar-view-menu";
+
            platformIconId: "toolbar-view-menu";
-
            onClicked: (myMenu.status == DialogStatus.Closed) ? myMenu.open() : myMenu.close()
+
-
 
+
-
 
+
         }
         }
-
 
     }
     }
-
 
 
}
}
 +
</pre>
 +
== MainPage.qml ==
-
 
+
<pre>
-
 
+
-
 
+
-
 
+
-
MainPage.qml:
+
-
 
+
-
 
+
import QtQuick 1.1
import QtQuick 1.1
-
import com.meego 1.0
+
import com.nokia.meego 1.0
import Qt 4.7
import Qt 4.7
import QtMobility.location 1.1
import QtMobility.location 1.1
Line 58: Line 43:
     id: mainPage
     id: mainPage
     tools: commonTools
     tools: commonTools
-
    //init GPS etc
+
 
-
    PositionSource {
+
-
        id: positionSource
+
-
        updateInterval: 1000
+
-
        //active: false
+
-
        active: gpsswitch.checked
+
-
    }
+
     function printableMethod(method) {
     function printableMethod(method) {
         if (method == PositionSource.SatellitePositioningMethod)
         if (method == PositionSource.SatellitePositioningMethod)
Line 76: Line 55:
         return "source error";
         return "source error";
     }
     }
 +
 +
    //init GPS etc
 +
    PositionSource {
 +
        id: positionSource
 +
        updateInterval: 1000
 +
        //active: false
 +
        active: gpsswitch.checked
 +
    }
 +
     Grid {
     Grid {
         id: positiondata
         id: positiondata
Line 84: Line 72:
         columns: 2
         columns: 2
         spacing: 5
         spacing: 5
-
        //visible: false
+
 
         Text {
         Text {
             id:latitudelabel
             id:latitudelabel
Line 136: Line 124:
         }
         }
     }
     }
-
        Row {
+
    Item {
-
            id: switchrow
+
        id: switchrow
-
            width: 300
+
        width: 300
-
            spacing: 10
+
        anchors.top:  positiondata.bottom
-
            anchors.top:  positiondata.bottom
+
        anchors.left:  positiondata.left
-
            anchors.left:  positiondata.left
+
        anchors.topMargin: 50
-
            anchors.topMargin: 50
+
 
         // Switch for power saving: toggle gps on/off
         // Switch for power saving: toggle gps on/off
         Text {
         Text {
Line 155: Line 143:
             anchors.left: switchtext.right
             anchors.left: switchtext.right
             anchors.leftMargin: 50
             anchors.leftMargin: 50
-
        }
+
        }
     }
     }
}
}
-
 
-
 
-
 
</pre>
</pre>

Revision as of 01:01, 26 November 2011

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
  • Modified by: Venemo

main.qml

import QtQuick 1.1
import com.nokia.meego 1.0

PageStackWindow {
    id: appWindow
    initialPage: mainPage

    MainPage {
        id: mainPage
    }
    ToolBarLayout {
        id: commonTools
        visible: true
        parent: appWindow.pageStack.currentPage

        Button {
            text: "View trackings"
            height: parent.height
        }
        ToolIcon {
            platformIconId: "toolbar-view-menu";
        }
    }
}

MainPage.qml

import QtQuick 1.1
import com.nokia.meego 1.0
import Qt 4.7
import QtMobility.location 1.1

Page {
    id: mainPage
    tools: commonTools

    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";
    }

    //init GPS etc
    PositionSource {
        id: positionSource
        updateInterval: 1000
        //active: false
        active: gpsswitch.checked
    }

    Grid {
        id: positiondata
        anchors.top: parent.top
        anchors.topMargin: 50
        anchors.left:  parent.left
        anchors.leftMargin: 10
        columns: 2
        spacing: 5

        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
        }
    }
    Item {
        id: switchrow
        width: 300
        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
        }
    }
}
Personal tools