Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Provide position through QGeoPositionInfoSource
Forum Updated to NodeBB v4.3 + New Features

Provide position through QGeoPositionInfoSource

Scheduled Pinned Locked Moved Unsolved General and Desktop
qgeopositioninfpositioning
8 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustAJ
    wrote on last edited by JustAJ
    #1

    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!

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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)?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @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)?

        J Offline
        J Offline
        JustAJ
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          J 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @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.

            J Offline
            J Offline
            JustAJ
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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?

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              J 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @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?

                J Offline
                J Offline
                JustAJ
                wrote on last edited by JustAJ
                #7

                @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.

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Ok, mixed it up :)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved