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. Adding Marker in QT QML Map
QtWS25 Last Chance

Adding Marker in QT QML Map

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qml mapqt quickc++udp
2 Posts 2 Posters 1.5k 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.
  • D Offline
    D Offline
    Double A
    wrote on 3 Jun 2019, 17:07 last edited by
    #1

    Good day developers!

    What I want is to add multiple marker in my qml Map, the data display in map is based on the receive data using UDP Sockets. For now i have a running code that display one marker only, but my goal is send multiple data and display it in my map using one MapQuickItem only. Is that possible in QT QML?

    I'm using the code below

    main.cpp

      int main(int argc, char *argv[])
     {
     QGuiApplication app(argc, argv);
     qmlRegisterType<BackEnd>("io.qt.examples.backend", 1, 0, "BackEnd");
     QQmlApplicationEngine engine;
     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
     return app.exec();
      }
    

    udp.cpp //I'm using this code to receive data.

    //
    ```  while (socket->hasPendingDatagrams()){
      QByteArray buffer;
      buffer.resize(socket->pendingDatagramSize());
      QHostAddress sender;
      quint16 port;
    
      socket->readDatagram(buffer.data(),buffer.size(),&sender,&port);
    
      hldr = tr("%1").arg(buffer.data());
    
      QStringList list1 = hldr.split(',');
      strLat = list1[0];
      strLon = list1[1];
    
     qDebug() << "Latitude: " << strLat;
     qDebug() << "Longitude: " << strLon;
    
     qDebug()<<"Message From: " << sender.toString();
     qDebug()<<"With Port Number " << port;
     qDebug()<<"Message: " << buffer;
    
     emit vesselLatChanged();
     emit vesselLonChanged();
        }
      }
    
      QString BackEnd::vesselLat()
     {
       m_vesselLat = strLat;
       qDebug() << m_vesselLat;
       return m_vesselLat;
      }
     QString BackEnd::vesselLon()
     {
       m_vesselLon = strLon;
       qDebug() << m_vesselLon;
       return m_vesselLon;
     }
     QString BackEnd::vesselSpeed()
     {
       m_vesselSpeed = strSpeed;
       qDebug() << m_vesselSpeed;
       return m_vesselSpeed;
      }
    
    Map.qml //I'm using this code to display map.
    
      Window {
      id: root
       width: 300
       height: 480
       visible: true
       visibility: "Maximized"
       property double latitude: backend.vesselLat
       property double longitude: backend.vesselLon
    
       BackEnd{
       id:backend
       }
    
       Plugin {
        id: mapPlugin
        name: "osm" 
        }
       Map {
            id: map
            anchors.fill: parent
            plugin: mapPlugin
            center: QtPositioning.coordinate(59.14, 14.15) 
            zoomLevel: 15
    
          MapQuickItem {
             id: marker
             anchorPoint.x: image.width
             anchorPoint.y: image.height
             coordinate {
                    latitude: latitude
                    longitude: longitude
                         }
             sourceItem: Image {
                     id: image
                     source: "qrc:/resources/marker.png"
    
                }
            }
    
         }
      }
    1 Reply Last reply
    0
    • K Offline
      K Offline
      KoneTaH
      wrote on 5 Jun 2019, 00:40 last edited by KoneTaH 6 May 2019, 00:42
      #2

      Why do you want to "display it in my map using one MapQuickItem only"? You will need to create multiple MapQuickItem instances to display multiple markers on map at once. You can create them statically (if their number is known in advance) or dynamically (if not).

      1 Reply Last reply
      0

      2/2

      5 Jun 2019, 00:40

      • Login

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