Access PositionSource object on python

Hi,
Using PositionSource I’m able to retrieve the GPS coordinates of my device, but I currently don’t know how to access to coordinates on python. On my python code, if I try to access to src.position.coordinate I get :

Cannot convert: QVariant(QGeoCoordinate)
None test 2
# File FirstPage.qml :
PositionSource {
      id: src
      updateInterval: 1000
      active: true
      preferredPositioningMethods: PositionSource.AllPositioningMethods

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

Python {
      id: python

      Component.onCompleted: {
          addImportPath(Qt.resolvedUrl('.'));

          importModule('main', function () {});

      }

      function gpsTest() {
          call('main.gps', [src], function() {});
      }

      onError: {
          // when an exception is raised, this error handler will be called
          console.log('python error: ' + traceback);
      }

      onReceived: {
          // asychronous messages from Python arrive here
          // in Python, this can be accomplished via pyotherside.send()
          console.log('got message from python: ' + data);
      }
}

# File main.py :
#!/usr/bin/env python3


import pyotherside


def gps(qobject):
    print(qobject, 'test 2')
    return qobject

I’m following this tutorial from the Sailfish Documentation.
Thank you in advance

I found it. Looking how pure-maps works helped me.

Instead declaring the function gpsTest, I call it directly from object PositionSource like this :

   PositionSource {
        id: src
        updateInterval: 1000
        active: true
        preferredPositioningMethods: PositionSource.AllPositioningMethods

        onPositionChanged: {
            var coord = src.position.coordinate
            console.log("Coordinate:", coord.longitude, coord.latitude);
            py.call("datadownloader.gps", [src.position.coordinate.latitude,
                                           src.position.coordinate.longitude],
                    function () {});
        }
    }

I modified datadownloader.gps to accept two parameters.

1 Like