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. QML Map View Mark Location By Lat Long

QML Map View Mark Location By Lat Long

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 827 Views
  • 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.
  • H Offline
    H Offline
    haris123
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0

    • Login

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