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 objects to the “Map” with addMapObject
Forum Updated to NodeBB v4.3 + New Features

Adding objects to the “Map” with addMapObject

Scheduled Pinned Locked Moved QML and Qt Quick
13 Posts 2 Posters 4.6k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    pascal95abc
    wrote on last edited by
    #3

    First of all: I am using Qt Quick 1.0 because I develop for 5th devices. (maybe this is informative)

    The code:
    @ Rectangle {
    id: r0
    anchors.fill: parent

        MapPolygon {
            id: polygon1
            border {color: "green"; width: 5}
            Coordinate {latitude:53.5*****;longitude: 8.5*****}
            Coordinate {latitude:53.5*****;longitude: 8.5*****}
            Coordinate {latitude:53.5*****;longitude: 8.5*****}
        }
    
        Map {
            id: map0
            plugin : Plugin {
                name : "nokia"
            }
            anchors.fill: parent
            size.width: parent.width
            size.height: parent.height
            zoomLevel: 10
            //pan: true // not so easy :(
            center: Coordinate {latitude:53.5*****;longitude: 8.5*****}
    
            Component.onCompleted: map.addMapObject(polygon1) // here is the procedure
        }
    }@
    

    Qt 4.7.3
    Symbian OS v9.4 / Symbian^1, S60 5th Edition
    on N97

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #4

      Your Map item is named "map0" not "map". The "map" in line 25 refers to the id of your Map element.

      If you change the procedure to
      @
      Component.onCompleted: map0.addMapObject(polygon1)
      @
      you should be ok.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pascal95abc
        wrote on last edited by
        #5

        Sorry, this was a typo because I removed some unimportant things for this post's code and accidentaly removed this as well.
        Then the error message would say something like identifier "map" not fount but it still says TypeError: Result of expression ‘map.addMapObject’ [undefined] is not a function.

        Qt 4.7.3
        Symbian OS v9.4 / Symbian^1, S60 5th Edition
        on N97

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pascal95abc
          wrote on last edited by
          #6

          Hello, the same problem occurs at "addCoordinate" for a "MapPolygon" to add a coordinate to it, too!

          I think I can't add map objects to other object. The error message is the same, just with the respective function's name.

          I still think it is something with QtQuick 1.1 and QtQuick 1.0 what I have to use because my Symbian 5th device doesn't find QtQuick 1.1, aswell as I heard, adding functions for maps are made available with QtQuick :(

          How to do so with QtQuick 1.0 then ?!
          (It is especially for N97 btw)

          Qt 4.7.3
          Symbian OS v9.4 / Symbian^1, S60 5th Edition
          on N97

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pascal95abc
            wrote on last edited by
            #7

            Hello.

            I want to add a coordinate to a MapPolygon called polygon1.
            addCoordinate doesn't work for me because I use QtQuick 1.0.
            So, this is what I wrote, without an error message but nothing happens at all:

            @MouseArea {
            anchors.fill: parent
            onPressed: {
            var px = mouse.x;
            var py = mouse.y;
            console.log("mouse clicked at X = " + px + ", Y = " + py);
            var newcoord = map0.toCoordinate(Qt.point(px, py));
            console.log("Add coordinate: ");
            console.log(newcoord.latitude + "," + newcoord.longitude);
            var objprefix = 'import QtQuick 1.0; import QtMobility.location 1.2; ';
            var objstring = objprefix+'Coordinate {latitude: '+ newcoord.latitude +'; longitude: '+newcoord.longitude+'}';
            console.log('objstr: '+objstring);
            var coordobj = Qt.createQmlObject(objstring, polygon1);

                // polygon1.addCoordinate(newcoord);  // doesn't work
                //newcoord.parent = polygon1;         // this neither
            
                map0.center = newcoord;
            
                console.log("finished.");
            }
            

            }
            @

            The idea is that the user clicks somewhere on the map and this coordinate is added to the polygon.

            All the console logs appear with correct coordinates and the map centers then at the clicked position very successfully!
            But the MapPolygon doesn't change on the map.

            By the way: I already tried to add a rectangle with the same method (differences in code: changed "objstring" and the parent polygon1->page)

            If it is interesting, here the other code:
            @Map {
            id: map0
            plugin: Plugin {
            name: "nokia"
            }
            anchors.fill: parent
            size.width: parent.width
            size.height: parent.height
            zoomLevel: 10
            center: Coordinate {
            latitude: 53.5****;
            longitude: 8.5***
            }

            // Component.onCompleted: map0.addMapObject(polygon1) // does NOT work!
            MapPolygon {
                id: polygon1
                border {
                    color: "red";
                    width: 4
                }
                Coordinate {
                    latitude: 53.****;
                    longitude: 8.****;
                }
                Coordinate {
                    latitude: 53.****;
                    longitude: 8.****
                }
                Coordinate {
                    latitude: 53.****;
                    longitude: 8.****
                }
            }
            

            }
            @

            And the polygon is clearly visible on my mobile device, but when I click somewhere, on the mobile phone nothing happens!

            THank you.
            This is very important for me because I need this feature to add coordinates to my polygon!!!

            Qt 4.7.3
            Symbian OS v9.4 / Symbian^1, S60 5th Edition
            on N97

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #8

              I merged these two threads because they are so closely-related.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pascal95abc
                wrote on last edited by
                #9

                Now, I managed to create a whole map (at runtime, of course):

                objstring would be expect of the imports:
                @Map { id: map1; plugin: Plugin { name: "nokia" } anchors.fill: parent; size.width: parent.width; size.height: parent.height; zoomLevel: 10; center: Coordinate { latitude: 53.; longitude: 8. } MapPolygon { id: polygon1; border { color: "red"; width: 4 } Coordinate { latitude: 53.; longitude: 8. } Coordinate { latitude: 53.; longitude: 8. } Coordinate { latitude: 53.; longitude: 8. } Coordinate { latitude: 53.; longitude: 8. } } } @
                ^ (This is one single line. )

                Now, I try on the whole polygon, let's see...

                Qt 4.7.3
                Symbian OS v9.4 / Symbian^1, S60 5th Edition
                on N97

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #10

                  bq. This is one single line.

                  Any particular reason?

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    pascal95abc
                    wrote on last edited by
                    #11

                    This was just for information, because then you know there are no strange break within a word or a command.

                    Qt 4.7.3
                    Symbian OS v9.4 / Symbian^1, S60 5th Edition
                    on N97

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #12

                      Would be easier to read if it were indented properly, etc.

                      Software Engineer
                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        pascal95abc
                        wrote on last edited by
                        #13

                        Now I added linebreaks for optical reasons:
                        @Map {
                        id: map1;
                        plugin: Plugin { name: "nokia" }
                        anchors.fill: parent;
                        size.width: parent.width;
                        size.height: parent.height;
                        zoomLevel: 10; center:
                        Coordinate { latitude: 53.; longitude: 8. }
                        MapPolygon { id: polygon1; border { color: "red"; width: 4 }
                        Coordinate { latitude: 53.; longitude: 8. }
                        Coordinate { latitude: 53.; longitude: 8. }
                        Coordinate { latitude: 53.; longitude: 8. }
                        Coordinate { latitude: 53.; longitude: 8. }
                        }
                        }
                        @

                        Qt 4.7.3
                        Symbian OS v9.4 / Symbian^1, S60 5th Edition
                        on N97

                        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