QML Map View Mark Location By Lat Long



  • Hi I need to mark multiple location on QML Map with latitude and longitude as input. I am able to mark a single location using below code but no idea how to mark multiple location,

    Here the code

     import QtQuick 2.0
     import QtPositioning 5.5
     import QtLocation 5.5
    
     Rectangle {
         width: 1200
         height: 640
    
    Plugin {
        id: myPlugin
        name: "osm"
    }
    
    PositionSource {
        id: positionSource
        property variant lastSearchPosition: locationOslo
        active: true
        updateInterval: 120000 // 2 mins
        onPositionChanged:  {
            var currentPosition = positionSource.position.coordinate
            map.center = currentPosition
            var distance = currentPosition.distanceTo(lastSearchPosition)
            if (distance > 500) {
                // 500m from last performed pizza search
                lastSearchPosition = currentPosition
                searchModel.searchArea = QtPositioning.circle(currentPosition)
                searchModel.update()
            }
        }
    }
    
    property variant locationOslo: QtPositioning.coordinate( 10.773, 76.651)
    
    GeocodeModel {
        id: geocodeModel
        plugin: map.plugin
        onStatusChanged: {
            if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error))
                map.geocodeFinished()
        }
        onLocationsChanged:
        {
            if (count == 1) {
                console.log("count---->"+count)
                map.center.latitude = get(0).coordinate.latitude
                map.center.longitude = get(0).coordinate.longitude
            }
        }
    
        Component.onCompleted: {
            geocodeModel.query = QtPositioning.coordinate( 10.773, 76.651)
            geocodeModel.update()
            //geocodeModel.query = QtPositioning.coordinate( 10.800, 76.651)
            //geocodeModel.update()
        }
    }
    
    
    
    
    
    Component {
        id: markerDelegate
    
        MapQuickItem {
            coordinate: locationData.coordinate//place.location.coordinate
            anchorPoint.x: image.width * 0.5
            anchorPoint.y: image.height
            sourceItem: Column {
            Image { id: image; source: "marker.png" }
            Text { text: "Location1";
                   font.bold: true }
            }
            }
    }
    
    
    
    
    Map {
        id: map
        anchors.fill: parent
        plugin: myPlugin;
        center: locationOslo
    
        zoomLevel: 13
    
    
    
        MapItemView {
    
            model: geocodeModel
            delegate: markerDelegate
    
        }
    }
    
    Connections {
        target: searchModel
        onStatusChanged: {
            if (searchModel.status == PlaceSearchModel.Error)
                console.log(searchModel.errorString());
        }
    }
    }
    

    How can I resolve the issue? Any hints or tips?


Log in to reply
 

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