Provide position through QGeoPositionInfoSource
-
Dear all, I am making an application which must show the location of a ship. The actual location comes from outside the application which I am making. To show the location, I want to make use of the LocationDisplay class. So I started a default ArcGIS application in Qt Creator (I tried both a QML and C++ app), and made a class, which is derived from QGeoPositionInfoSource, according to this example, linked by LDanzinger-esristaff, also on this forum. However, I just can't seem to get it to work. It seems I just don't understand it, and to be hones I'm getting a bit frustrated :)
My code is as follows:
#ifndef SHIPPOSITIONSOURCE_H #define SHIPPOSITIONSOURCE_H #include <QGeoPositionInfoSource> class ShipPositionSource : public QGeoPositionInfoSource { Q_OBJECT public: explicit ShipPositionSource(QObject* parent = nullptr); ~ShipPositionSource(); QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const override; PositioningMethods supportedPositioningMethods() const override; int minimumUpdateInterval() const override; QGeoPositionInfoSource::Error error() const override; public slots: void startUpdates() override; void stopUpdates() override; void requestUpdate(int timeout = 0) override; QGeoPositionInfo currentPosition; QGeoPositionInfoSource::Error lastError = QGeoPositionInfoSource::NoError; bool started; }; #endif // SHIPPOSITIONSOURCE_H
That was the header, here the source:
#include "shippositionsource.h" ShipPositionSource::ShipPositionSource(QObject* parent) : QGeoPositionInfoSource(parent) { setUpdateInterval(500); currentPosition.setCoordinate(QGeoCoordinate(52.920905, 4.862173)); emit positionUpdated(currentPosition); } ShipPositionSource::~ShipPositionSource() {} void ShipPositionSource::startUpdates() { if(started) return; started = true; //TODO: start communication with bridge } void ShipPositionSource::stopUpdates() { if(!started) return; started = false; //TODO: stop communication with bridge } void ShipPositionSource::requestUpdate(int timeout) { Q_UNIMPLEMENTED(); } QGeoPositionInfo ShipPositionSource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const { Q_UNUSED(fromSatellitePositioningMethodsOnly); return currentPosition; } QGeoPositionInfoSource::PositioningMethods ShipPositionSource::supportedPositioningMethods() const { return QGeoPositionInfoSource::PositioningMethod::NoPositioningMethods; } int ShipPositionSource::minimumUpdateInterval() const { return updateInterval(); } QGeoPositionInfoSource::Error ShipPositionSource::error() const { return lastError; }
I made a Quick C++ app, called TestProject, and in TestProject.cpp I only edited the TestProject::setMapView method with the following lines:
m_mapView = mapView; m_mapView->locationDisplay()->setPositionSource(&positionSource); m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Recenter); m_mapView->locationDisplay()->start(); m_mapView->setMap(m_map);
The result is that I don't see any location updated, or the map centering on the position I gave in the constructor. I must be doing something wrong or I don't understand something, but I don't see what. I would be very thankful for hints and tips!
-
@JustAJ said in Provide position through QGeoPositionInfoSource:
locationDisplay
What type of Qt class is this? I think this is no Qt class but on from ESRI ArcGIS runtime SDK ( https://developers.arcgis.com/qt/latest/cpp/api-reference/esri-arcgisruntime-locationdisplay.html ) so you should better ask here as we don't have any experience with this library.
Also - where did you define positionSource - are you sure it's alive after you leave the function (I would guess no)? -
@Christian-Ehrlicher said in Provide position through QGeoPositionInfoSource:
@JustAJ said in Provide position through QGeoPositionInfoSource:
locationDisplay
What type of Qt class is this? I think this is no Qt class but on from ESRI ArcGIS runtime SDK ( https://developers.arcgis.com/qt/latest/cpp/api-reference/esri-arcgisruntime-locationdisplay.html ) so you should better ask here as we don't have any experience with this library.
Also - where did you define positionSource - are you sure it's alive after you leave the function (I would guess no)?I am terribly sorry, I mixed up some stuff. This is indeed from the ArcGIS SDK. I will go ask there.
Yes, positionSource is alive at that position. I defined it as a private attribute of the TestProject class, in the header
-
@JustAJ said in Provide position through QGeoPositionInfoSource:
I defined it as a private attribute of the TestProject class, in the header
I just asked because the other members seems to be prefixed with 'm_'. Also I would check QGeoPositionInfoSource::error() and other functions provided by QGeoPositionInfoSource to see if it is really valid.
-
@Christian-Ehrlicher said in Provide position through QGeoPositionInfoSource:
@JustAJ said in Provide position through QGeoPositionInfoSource:
I defined it as a private attribute of the TestProject class, in the header
I just asked because the other members seems to be prefixed with 'm_'. Also I would check QGeoPositionInfoSource::error() and other functions provided by QGeoPositionInfoSource to see if it is really valid.
I've worked quite some time in a .NET environment, so I'm not very fond of the prefixes. This code was from an example, which I modified to my preferences.
Regarding the error() method, it is a pure virtual method, so besides my own implementation, no useful information can be gotten. -
@JustAJ said in Provide position through QGeoPositionInfoSource:
so besides my own implementation
What does this mean? You wrote an own QGeoPositionInfoSource? Did you actually check if it is working correctly?
-
@Christian-Ehrlicher said in Provide position through QGeoPositionInfoSource:
@JustAJ said in Provide position through QGeoPositionInfoSource:
so besides my own implementation
What does this mean? You wrote an own QGeoPositionInfoSource? Did you actually check if it is working correctly?
I don't think I understand what you mean... I made my own class which inherits from QGeoPositionInfoSource, as you can see in the code I provided. The QGeoPositionInfoSource::error() you mentioned is a pure virtual method, so I cannot use this method to troubleshout if something goes wrong in QGeoPositionInfoSource, that's what I mean.
-
Ok, mixed it up :)