1

Is there a way to access the status and the XY-coordinates from a GPS-connection established by the GPS-widget in QGIS 3 via python? I want to establish the connection with the widget to have better control of the connection (like changing ports) and status checks, but need the coordinates inside a python plugin.

  • This is a good one! There is a panel to view GPS in the menu View- Panels- GPS information. There must be a way to get that info. – Cary H Dec 21 '18 at 19:17
  • Seems to be a bigger issue.. even in the QGIS mailinglist I got no reaction to this question. – Firefly Dec 22 '18 at 9:23
  • 1
    When keeping the map always centered over the current position, it is possible to get the coordinates with canvas = iface.mapCanvas() canvas.center() . – Firefly Dec 28 '18 at 21:19
  • 1
    gis.stackexchange.com/questions/187985/… This is a QGIS 2 response but we can look for the same function in QGIS 3.4 docs – Cary H Feb 20 at 16:13
0

Thanks to the comment of Cary H I found a solution.

QGIS 2 uses

QgsGpsConnectionRegistry().instance()

QGIS 3 now uses

QgsApplication.gpsConnectionRegistry()

So using the following code

connectionRegistry = QgsApplication.gpsConnectionRegistry()
connectionList = connectionRegistry.connectionList()
GPSInfo = connectionList[0].currentGPSInformation()

After that it is possible to access all information of the widget-gps-connection using for example

GPSInfo.elevation
GPSInfo.latitude

All available commands are listed at https://qgis.org/pyqgis/3.2/core/Gps/QgsGpsInformation.html

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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