Meego Wiki
Views

QML/Get GPS data

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "To be added as soon as I get my own code cleaned from unnecessary stuff... --~~~~")
Line 1: Line 1:
-
To be added as soon as I get my own code cleaned from unnecessary stuff... --[[User:Ossipena|Ossipena]] 16:10, 23 July 2011 (UTC)
+
Code snippet that draws ui and shows GPS data and accuracy, also with GPS on/off switch if one wants to conserve power.
 +
 
 +
<pre>
 +
// Made by: Ossipena
 +
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
 +
        }
 +
    }
 +
    Flow {
 +
        //LeftToRight: true
 +
        width: mainPage.width
 +
        id: buttonarea
 +
        anchors.top:  positiondata.bottom
 +
        anchors.topMargin: 50
 +
        anchors.left:  positiondata.left
 +
        spacing: 50
 +
        Row {
 +
            id: switchrow
 +
            width: 300
 +
            spacing: 10
 +
            anchors.top:  parent.top
 +
            anchors.left:  parent.left
 +
        // 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
 +
        }
 +
    }
 +
    Button {
 +
        id: savebutton
 +
        text: "Save"
 +
        width: 300
 +
        visible: true
 +
        //This button saves coordinates, not implemented (yet)
 +
    }
 +
}
 +
}
 +
 
 +
 
 +
</pre>

Revision as of 13:44, 24 July 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
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
        }
    }
    Flow {
        //LeftToRight: true
        width: mainPage.width
        id: buttonarea
        anchors.top:  positiondata.bottom
        anchors.topMargin: 50
        anchors.left:  positiondata.left
        spacing: 50
        Row {
            id: switchrow
            width: 300
            spacing: 10
            anchors.top:  parent.top
            anchors.left:  parent.left
        // 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
         }
    }
    Button {
        id: savebutton
        text: "Save"
        width: 300
        visible: true
        //This button saves coordinates, not implemented (yet)
    }
}
}


Personal tools