Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

It's strangely hard to find any documentation on accessing geolocation information for Ubuntu Touch specifically and even Qt5 more generally. The Qt Mobility APIs provided this in Qt4, and they seem to have been split into separate libraries in Qt5. These libraries were apparently removed from the Qt 5 distribution and are now considered optional add-on modules. As they are now "add-ons," the Qt website doesn't seem to publish their documentation anymore. There are Ubuntu packages for them, but installing the SDK doesn't actually pull them in. So it is unclear if they will be available on the phone or not.

The correct package seems to be qtdeclarative5-qtlocation-plugin Install qtdeclarative5-qtlocation-plugin, which can be accessed in Qml with import QtLocation 5.0

Trying to simply get latitude and longitude has been an exercise in futility. Looking at older Qt4 docs, I tried:

import QtQuick 2.0
import QtLocation 5.0


PositionSource {
    id: src
    updateInterval: 1000
    active: true

    onPositionChanged: {
        var coord = src.position.coordinate;
        console.log("Coordinate:", coord.longitude, coord.latitude);
        }
}

Sadly, this just segfaults...

So my question, simply stated, is how can you access geolocation information on Ubuntu Touch in Qml?

share|improve this question
    
This is a possible duplicate of askubuntu.com/questions/303508/… –  alci Sep 13 '13 at 17:18
    
Basically, Qt Location in Qt5 does not seem to be finished yet. It might be targeted at Qt5.2. Jolla includes a retroported beta version in its Sailfish SDK, maybe Ubuntu could do the same ? –  alci Sep 13 '13 at 17:20
    
I obviously saw that question, as it's linked in mine. I don't think their duplicates. As to Qt Location being finished or not, Ubuntu seems to be shipping a git snapshot. The current version is 5.0~git20130805 –  andrewsomething Sep 13 '13 at 19:23

1 Answer 1

I think it did not work for you due to GPS not being enabled on the device. The following code sample worked without segfaulting on my laptop. On the device, it takes about 1-2 mins to get the GPS lock since AGPS hasn't landed yet.

import QtQuick 2.2
import Ubuntu.Components 1.1.
import QtPositioning 5.2

MainView {
    id: mainView

    applicationName: "me.nik90.gpsapp"
    useDeprecatedToolbar: false

    width: units.gu(100)
    height: units.gu(75)

    Page {
        id: page

        title: "GPS"

        PositionSource {
            id: src

            updateInterval: 1000
            active: true

            onPositionChanged: {
                var coord = src.position.coordinate;
                console.log("Coordinate: " + coord.longitude + ":" + coord.latitude);
            }
        }

        Label {
            text: "Coordinate: " + src.coord.longtitude + ":" + src.coord.latitude;
        }
   }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.