Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

What is the correct way to change coordinates with GeocodeModel?



  • import QtQuick 2.0
    import QtLocation 5.12
    import QtPositioning 5.12
    
    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: endeAtirador
            street: rua
        }
    
        GeocodeModel{
    
            id: geoModel
            plugin: osm
            autoUpdate: false
    
            onLocationsChanged: {
    
                if(count > 0){
    
                    tgMarker.coordinate = get(0).coordinate
    
                    query.addWaypoint(QtPositioning.coordinate(latitude, longitude))
                    query.addWaypoint(get(0).coordinate)
                    route.update()
    
                    console.log("Coordenadas: ", get(0).coordinate)
                }
    
            }
        }
    
        Map{
    
           id: mapa
           zoomLevel: 17
           anchors.fill: parent
           center: QtPositioning.coordinate(latitude, longitude)
           plugin: osm
    
           RouteModel{
    
               id: route
               plugin: osm
               autoUpdate: false
               query: RouteQuery{id: query}
    
           }
    
           Component.onCompleted: {
               addMapItem(tgMarker)
    
               geoModel.query = endeAtirador
               geoModel.update()
    
           }
    
        }
    
    }
    

    I'm trying to create a route from one point to another, although it was getting the coordinates of the address I can not change the location of the other items with it


Log in to reply