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. geocode() form QGeoCodingManager class not returning anything after passing an address.
QtWS25 Last Chance

geocode() form QGeoCodingManager class not returning anything after passing an address.

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 730 Views
  • 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.
  • C Offline
    C Offline
    CaptainJuice
    wrote on last edited by
    #1

    Hey guys! I feel like I almost have geocode() working but I pass an address to geocode() and it returns an empty list ( longitude gets set to -1 below). Any tips would be greatly appreciated!
    #include "mapactions.h"
    #include <QGeoPositionInfoSource>
    #include <QGeoServiceProvider>
    #include <QGeoCodeReply>
    #include <QGeoCodingManager>
    #include <QGeoAddress>
    #include <QGeoCoordinate>
    #include <QGeoLocation>
    #include <QGeoShape>

    void MapFunctions::getmyaddress()
    {
    // QMap<QString,QVariant> params;
    // params["osm.geocoding.host"] = "https://nominatim.openstreetmap.org";
    QGeoServiceProvider* geoSrv = new QGeoServiceProvider( "osm");
    QGeoCodingManager *geoCoder = geoSrv->geocodingManager();
    QGeoAddress addr;
    addr.setCountry( "Canada" );
    addr.setCity("Toronto");
    QGeoCodeReply *geoCode = geoCoder->geocode(addr);
    if(geoCode->error()!= geoCode->NoError)
    {
    latitude = 14;
    }
    if((geoCode->locations()).isEmpty())
    {
    longitude =-1.0;
    return;
    }
    longitude = (geoCode->locations()).first().coordinate().longitude();
    latitude = (geoCode->locations()).first().coordinate().latitude();
    }

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

      Please read the documentation - the call only starts the geocoding. You have to connect to the appropriate signals.

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

      C 1 Reply Last reply
      1
      • C Offline
        C Offline
        CaptainJuice
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Please read the documentation - the call only starts the geocoding. You have to connect to the appropriate signals.

          C Offline
          C Offline
          CaptainJuice
          wrote on last edited by
          #4

          @Christian-Ehrlicher Hey, thanks for the reply! I tried implementing the slot handleFinish() but the values I'm getting are wonky, however, the list is no longer empty! I feel like the issue could be due to me making QGeoCodeReply *geoCode public as I was unsure how to pass it to the slot. Any tips are greatly appreciated!
          69ea174d-8825-43eb-bb49-94d3479935d7-image.png

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

            Sorry but this code is neither correct in any way nor does it compile at all. Please learn basic c++ and take a look at the Qt signals/slots examples.

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

            C 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              Sorry but this code is neither correct in any way nor does it compile at all. Please learn basic c++ and take a look at the Qt signals/slots examples.

              C Offline
              C Offline
              CaptainJuice
              wrote on last edited by CaptainJuice
              #6

              @Christian-Ehrlicher Ok, thankyou for your help. I have reviewed my code and reviewed the documentation. The slots and signals are now recognized but I am still not getting reasonable values. The issue is that neither slots are being called. If you could point me in the right direction that would be great.06de09d3-349b-42cf-8f48-2326feea308d-image.png

              jsulmJ 1 Reply Last reply
              0
              • C CaptainJuice

                @Christian-Ehrlicher Ok, thankyou for your help. I have reviewed my code and reviewed the documentation. The slots and signals are now recognized but I am still not getting reasonable values. The issue is that neither slots are being called. If you could point me in the right direction that would be great.06de09d3-349b-42cf-8f48-2326feea308d-image.png

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @CaptainJuice Are you sure handleError is not called? How did you check that?

                Also, please post your code as text, not screen-shots.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                C 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @CaptainJuice Are you sure handleError is not called? How did you check that?

                  Also, please post your code as text, not screen-shots.

                  C Offline
                  C Offline
                  CaptainJuice
                  wrote on last edited by
                  #8

                  @jsulm Sorry about that, will make sure to change that next time. I know it never enters either one of handleError() or handleFinish() because in my QML i have,

                  Component.onCompleted: {
                  MapFunctions.getmyaddress();
                  console.log("Coordinate:", MapFunctions.getlatitude());
                  console.log("Coordinate:", MapFunctions.getlongitude());
                  }

                  for the application window. If I set values in those handle() functions they do not get reflected in the console log. For example I set longitude= 14 in handleFinish() and I comment out the other code and this has no effect on the output. For handleError() the values do not get set to -1 so it doesn't get called.

                  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