Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Country code/name from coordinates?
Qt 6.11 is out! See what's new in the release blog

Country code/name from coordinates?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 1.9k 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.
  • E Offline
    E Offline
    ErnestJ
    wrote on last edited by
    #1

    Hello :)
    Is there a possibility to get country code/name from coordinates( latitude & longitude )?
    I would like to provide some feature on the base of country.
    I would be grateful for any help or link :)

    raven-worxR 1 Reply Last reply
    0
    • E ErnestJ

      Hello :)
      Is there a possibility to get country code/name from coordinates( latitude & longitude )?
      I would like to provide some feature on the base of country.
      I would be grateful for any help or link :)

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @ErnestJ
      the term you are looking for is "reverse geocoding"
      GeoCodeModel provides such functionality for example

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      5
      • E Offline
        E Offline
        ErnestJ
        wrote on last edited by
        #3

        @raven-worx
        Thank you for help. While trying out example from your link I encountered a network error.

            Plugin {
                    id: mapPlugin
                    name: "osm"
            }
            GeocodeModel {
                id: geocodeModel
                plugin: mapPlugin
                autoUpdate: false
            }
            MouseArea {
                id: mouseArea
                x: 75
                y: 101
                width: 200
                height: 200
                onClicked: {
                    geocodeModel.query = "10.075252, 19.934158"
                    geocodeModel.update()
                    if(geocodeModel.count > 0)
                        console.log( geocodeModel.get(0).address.country )
                    else
                        console.log("no connection")
                }
            }
        

        Always first MouseArea click gives "no connection", but second shows correct result. Could you tell me why is it? Should I somehow connect to osm first?
        Output:

        qml: no connection
        QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once QUrl("https://nominatim.openstreetmap.org/search?q=10.075252, 19.934158&format=json&accept-language=en&polygon_geojson=1&addressdetails=1")
        qml: Chad
        
        raven-worxR 1 Reply Last reply
        0
        • E ErnestJ

          @raven-worx
          Thank you for help. While trying out example from your link I encountered a network error.

              Plugin {
                      id: mapPlugin
                      name: "osm"
              }
              GeocodeModel {
                  id: geocodeModel
                  plugin: mapPlugin
                  autoUpdate: false
              }
              MouseArea {
                  id: mouseArea
                  x: 75
                  y: 101
                  width: 200
                  height: 200
                  onClicked: {
                      geocodeModel.query = "10.075252, 19.934158"
                      geocodeModel.update()
                      if(geocodeModel.count > 0)
                          console.log( geocodeModel.get(0).address.country )
                      else
                          console.log("no connection")
                  }
              }
          

          Always first MouseArea click gives "no connection", but second shows correct result. Could you tell me why is it? Should I somehow connect to osm first?
          Output:

          qml: no connection
          QNetworkReplyHttpImplPrivate::_q_startOperation was called more than once QUrl("https://nominatim.openstreetmap.org/search?q=10.075252, 19.934158&format=json&accept-language=en&polygon_geojson=1&addressdetails=1")
          qml: Chad
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @ErnestJ said in Country code/name from coordinates?:

          Always first MouseArea click gives "no connection", but second shows correct result. Could you tell me why is it?

          of course , because (like any other network request) the result comes asynchronously.
          So rather do something like this:

          GeocodeModel {
              ...
              onCountChanged: {
                  if( count > 0 )
                        console.log( geocodeModel.get(0).address.country )
              }
          }
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2

          • Login

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