[Interest] Qt positioning

Federico Buti bacarozzo at gmail.com
Tue Aug 11 14:24:03 CEST 2015


Hi list,

I was playing around with positioning on Android and I'm not sure if I'm
using it properly. I would like to update the position of the cellphone/app
ASA the user taps on a button. To achieve this result I've setup my project
as follows:

1) added the positioning to the pro:

    QT += positioning


2) Added the positioning import to the involved QML file:

    import QtPositioning 5.2   // should/must be "import QtPositioning 5.3"
or others?


3) Added permissions to manifest

     <uses-permission android:name="android.permission.INTERNET"/>

   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

   <uses-permission
android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>

   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>



4) Added the following code:


 StyledButton {

                id: mapMarkerButton

                Layout.alignment: Qt.AlignHCenter

                Layout.preferredHeight: 120 * Params.scaleFactor

                Layout.preferredWidth: 120 * Params.scaleFactor

                sourceUncheckedImage: "qrc:///pics/pin.png"


                onClicked: {   gpsPosition.start()  }

            }


​PositionSource {

            id: gpsPosition

            active:
​false


            onPositionChanged: {

​
gpsPosition.st
​op()
​

               ​
var coord = position.coordinate;

                updateCoordinatesRecord(coord.latitude,
coord.longitude) //41.902222, 12.492222)

            }


            onSourceErrorChanged: {
​​

                notify("
​...
")

            }

}​


​The idea was to activate the GPS ​only when required, update the value
(probably with a busy dialog on screen) and deactivate it. I could have
used the update() method, I know.

Now, if I execute the code on a device with GPS turned off, I've the error
"PositionSource.ClosedError". Instead, on the same device with GPS turned
on the position is never updated. The same occurs in a newly created
project with just this code added.

Qt version is 5.5

What am I missing? What am I doing wrong? The default dialog for GPS
activation (i.e. the one shown by Googlemaps for instance) is not shown
when position acquisition is started?


Thanks everyone for your time,
F.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150811/d3d68a90/attachment.html>


More information about the Interest mailing list