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

Qt Location: Marking multi addresses on Map



  • Thank you for looking here !

    The one question is: How can I use the same plugin connection on both qml & cpp files?

    qml file > Plugin{ id: mapPlugin name: "osm" }
    and ...
    cpp file > QgeoServiceProvider, QGeoCodingManager

    (one direction and other direction qml->cpp and cpp->qml plugin)

    Main question: I draw multi points on map using the bellow code.
    My question is how can I transform the addMarker() function instead of giving Latitude/Longitude to give the address city/street/zip etc names ?

    MapView.qml

    Item
    {
        id: window
    
        Plugin
        {
            id: mapPlugin
            name: "osm"
        }
    
        function addMarker(name, lat, lon)
        {
            var component = Qt.createComponent("qrc:///qml/marker.qml")
            var item = component.createObject(window, {coordinate: QtPositioning.coordinate(lat, lon), labelText: name})
            map.addMapItem(item)
        }
    
        Map
        {
            id: map
            anchors.fill: parent
            plugin: mapPlugin
            center: QtPositioning.coordinate(38, 23)
            zoomLevel: 8
    
            Component.onCompleted:
            {
                addMarker("house", 38.0, 23.0)
                addMarker("lake", 38.2, 23.2)
                addMarker("church", 38.3, 23.3)
            }
        }
    }
    
    

    marker.qml

    MapQuickItem
    {
        id: marker
        anchorPoint.x: marker.width / 2
        anchorPoint.y: marker.height / 2
        property string labelText
    
        sourceItem: Item
        {
            Image
            {
                id: icon
                source: "///images/point.png"
            }
    
            Rectangle
            {
                id: tag
                anchors.centerIn: label
                width: label.width + 4
                height: label.height + 2
                color: "black"
            }
    
            Label
            {
                id:label
                text: labelText
            }
        }
    }
    
    

    to be something like ...

    
        function addMarker(Street, City, Country, State, PostalCode)
        {
             Address {
                       id :markAddress
                       street: Street
                       city: City
                       country: Country
                       state : State
                       postalCode: PostalCode
            }
            
            ...
            map.addMapItem(itemAddress)
        }
    
    

    or this one ...

        GeocodeModel 
        {
              id: geocodeModel
              plugin: mapPlugin
              autoUpdate: false
        }
    
        function addMarker(onelineaddress)  //"53 Praxitelis St, Plains, Greece"
        {
              geocodeModel.query = onelineaddress
              geocodeModel.update()
              ...
              ...
              map.addMapItem(itemAddress)
        }
    
    

Log in to reply