GeocodeModel does not work



  • import QtQuick 2.0
    import QtLocation 5.11
    import QtPositioning 5.11
    
    Rectangle{
    
        // Icone que representa um marcador no mapa
        Image {
            id: ic_marker
            source: "qrc:///icons/icons/ic_map_marker.svg"
            sourceSize.width:  50
            sourceSize.height: 50
        }
    
        // Plugin responsavel por executar requisicoes de dados para o mapa
        Plugin{
            id: osm
            name: "osm"
            PluginParameter{name: "osm.useragent"; value: "TGAdmin"}
            PluginParameter{name: "osm.mapping.custom.host"; value: "https://tile.openstreetmap.org"}
            PluginParameter{name: "osm.mapping.providersrepository.disabled"; value: true}
        }
    
        // Marcador da posicao do tiro de guerra no mapa
        MapQuickItem{
            id: tgMarker
            anchorPoint.x: tgMarker.width / 4
            anchorPoint.y: tgMarker.height
            coordinate: QtPositioning.coordinate(latitude, longitude)
            sourceItem: ic_marker
        }
    
        Address {
            id :fromAddress
            street: "Sandakerveien 116"
            city: "Oslo"
            country: "Norway"
            state : ""
            postalCode: "0484"
        }
    
        GeocodeModel{
            id: geoAt
            plugin: osm
            autoUpdate: false
        }
    
        // O mapa em si
        Map{
    
            id: mapa
            anchors.fill: parent
            plugin: osm
            zoomLevel: 17
            center: QtPositioning.coordinate(latitude, longitude)
    
            Component.onCompleted: {
                addMapItem(tgMarker)
    
                geoAt.query = fromAddress
                geoAt.update()
    
                console.log("Enderecos obtidos: ", geoAt.count)
            }
    
        }
    
    }
    

    I've been trying to get the geographic coordinates of an address for about a week but nothing is returned.

    The rest of the map works normally, I need this because the system I'm developing must trace a route to the address provided by the register.



  • @Samuel-Ives
    GeocodeModel's request is not synchronous. It means your code will always print Enderecos obtidos: 0, because the count has not changed.

    If you need to capture the coordinate when the request ends, you may connect a function to locationsChanged signal.
    See a example:

    GeocodeModel{
            id: geoAt
            plugin: osm
            autoUpdate: false
            onLocationsChanged: { // when reply
                if (count > 0){ // found a location
                    console.log(get(0).coordinate); // print the coordinate
                }
            }
        }
    


  • still without any coordinates, I made this small change as suggested:

    GeocodeModel{
            id: geoAt
            plugin: osm
            autoUpdate: false
            onLocationsChanged: {
    
                if(count > 0){
    
                    mapa.Center = QtPositioning.coordinate(get(0).coordinate.latitude, get(0).coordinate.longitude)
                    console.log("Coordenadas: ", get(0).coordinate.latitude, " ", get(0).coordinate.longitude)
    
                }
    
            }
        }
    
        // O mapa em si
        Map{
    
            id: mapa
            anchors.fill: parent
            plugin: osm
            zoomLevel: 17
            center: QtPositioning.coordinate(latitude, longitude)
    
            Component.onCompleted: {
                addMapItem(tgMarker)
    
                geoAt.query = fromAddress.text
                console.log("Endereco: ", fromAddress.text)
                geoAt.update()
    
    
                console.log("Enderecos obtidos: ", geoAt.count)
            }
    
        }
    

    And this is the result:

    0_1557236981412_6328759f-e93f-4c0c-8b04-a0fcd18c0872-image.png

    *This time I also tried with a text in place of the address


  • Moderators

    @Samuel-Ives
    i know that GeoCodeModel (using osm) was broken in Qt 5.10 (or at least in the meantime broken) and working again with 5.12.
    I can't tell if that was still the case with Qt 5.11



  • esri is not working either, I do not think it's a plugin specific problem



  • @Samuel-Ives could it be possible you do network traffic capture (i.e. using Wireshark) to check if the request(s) made by the plugin(s) (either osm or esri) are reaching the Internet and what response(s) do you received, if any?
    At least you could figure out if the problem is the request/response (network operations) or the display of information received?



  • @Samuel-Ives
    I got the same behavior when i used geoAt.query = fromAddress.text instead of geoAt.query = fromAddress

    Edit: It is possible to know if something wrong happens if you connect onStatusChanged signal with a function.

    onStatusChanged: {
        if(status === GeocodeModel.Ready){
            console.log("Sucess, the request has been found "+count+" result(s).");
        }
        else if(status === GeocodeModel.Error){
            console.log("Error: " + errorString);
        }
    }
    


  • onStatusChanged: {
    
                switch(geoAt.status){
    
                case GeocodeModel.Loading:
                    console.log("Loading")
                    break;
    
                case GeocodeModel.Ready:
                    console.log("Ready")
                    break;
    
                case GeocodeModel.Error:
                    console.log("Error: ", errorString)
                    break;
    
                }
    
            }
    

    I got this

    qml: Endereco: Sandakerveien 116<br/>0484 Oslo<br/>Norway
    qml: Loading
    qml: Enderecos obtidos: 0
    qt.network.ssl: QSslSocket::connectToHostEncrypted: TLS initialization failed
    qml: Error: TLS initialization failed

    The strangest thing is that I do not remember any time using SSL



  • @Samuel-Ives

    The strangest thing is that I do not remember any time using SSL

    From you 1st post:

    PluginParameter{name: "osm.mapping.custom.host"; value: "https://tile.openstreetmap.org"}
    

    Are you still using the same values? if so, that could be the answer...



  • @Samuel-Ives
    https://doc.qt.io/qt-5/location-plugin-osm.html#overview

    Since Qt 5.9.6 the default nominatim endpoint, used for geocoding and places, has also changed to HTTPS-only.



  • Well, I compiled the openssl source code, I added the libraries in my project and added the dlls, but it still has the same error





  • the version returned was OpenSSL 1.0.2p, and the one I compiled was 1.1.1, could that influence something? What I find strange is that I'm not using a ssl resource directly, just that url, the compiler does not accuse me of linking errors regarding openssl



  • Problem solved, I downloaded the dlls from here and it worked http://slproweb.com/products/Win32OpenSSL.html, I'm already getting the coordinates, the libraries were not being loaded because they had a different name


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.