April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

adding objects to the “Map” with addMapObject

 

Hello.

Always when I try to add an object to the map (exactly following this explanation [doc.qt.nokia.com]) I get this error message:
TypeError: Result of expression ‘map.addMapObject’ [undefined] is not a function.

Hope someone can help.

 Signature 

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

12 replies

April 11, 2012

mlong mlong
Robot Herder
1551 posts

Can you provide the pertinent part of your code where you define map and where you’re trying to use addMapObject, please?

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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

The code:

  1.     Rectangle {
  2.         id: r0
  3.         anchors.fill: parent
  4.  
  5.         MapPolygon {
  6.             id: polygon1
  7.             border {color: "green"; width: 5}
  8.             Coordinate {latitude:53.5*****;longitude: 8.5*****}
  9.             Coordinate {latitude:53.5*****;longitude: 8.5*****}
  10.             Coordinate {latitude:53.5*****;longitude: 8.5*****}
  11.         }
  12.  
  13.         Map {
  14.             id: map0
  15.             plugin : Plugin {
  16.                 name : "nokia"
  17.             }
  18.             anchors.fill: parent
  19.             size.width: parent.width
  20.             size.height: parent.height
  21.             zoomLevel: 10
  22.             //pan: true // not so easy :(
  23.             center: Coordinate {latitude:53.5*****;longitude: 8.5*****}
  24.  
  25.             Component.onCompleted: map.addMapObject(polygon1) // here is the procedure
  26.         }
  27.     }

 Signature 

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

April 11, 2012

mlong mlong
Robot Herder
1551 posts

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

  1. Component.onCompleted: map0.addMapObject(polygon1)

you should be ok.

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 11, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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.

 Signature 

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

April 12, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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)

 Signature 

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

April 13, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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:

  1. MouseArea {
  2.     anchors.fill: parent
  3.     onPressed: {
  4.         var px = mouse.x;
  5.         var py = mouse.y;
  6.          console.log("mouse clicked at X = " + px + ",  Y = " + py);
  7.         var newcoord = map0.toCoordinate(Qt.point(px, py));
  8.          console.log("Add coordinate: ");
  9.          console.log(newcoord.latitude + "," + newcoord.longitude);
  10.         var objprefix = 'import QtQuick 1.0; import QtMobility.location 1.2; ';
  11.         var objstring = objprefix+'Coordinate {latitude: '+ newcoord.latitude +'; longitude: '+newcoord.longitude+'}';
  12.          console.log('objstr: '+objstring);
  13.         var coordobj = Qt.createQmlObject(objstring, polygon1);
  14.  
  15.         // polygon1.addCoordinate(newcoord);  // doesn't work
  16.         //newcoord.parent = polygon1;         // this neither
  17.  
  18.         map0.center = newcoord;
  19.  
  20.         console.log("finished.");
  21.     }
  22. }

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:

  1. Map {
  2.     id: map0
  3.     plugin: Plugin {
  4.         name: "nokia"
  5.     }
  6.     anchors.fill: parent
  7.     size.width: parent.width
  8.     size.height: parent.height
  9.     zoomLevel: 10
  10.     center: Coordinate {
  11.         latitude: 53.5****;
  12.         longitude: 8.5***
  13.     }
  14.  
  15.     // Component.onCompleted: map0.addMapObject(polygon1) // does NOT work!
  16.     MapPolygon {
  17.         id: polygon1
  18.         border {
  19.             color: "red";
  20.             width: 4
  21.         }
  22.         Coordinate {
  23.             latitude: 53.****;
  24.             longitude: 8.****;
  25.         }
  26.         Coordinate {
  27.             latitude: 53.****;
  28.             longitude: 8.****
  29.         }
  30.         Coordinate {
  31.             latitude: 53.****;
  32.             longitude: 8.****
  33.         }
  34.     }
  35. }

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!!!

 Signature 

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

April 13, 2012

mlong mlong
Robot Herder
1551 posts

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

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 13, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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

objstring would be expect of the imports:

  1. 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…

 Signature 

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

April 14, 2012

mlong mlong
Robot Herder
1551 posts

This is one single line.

Any particular reason?

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 14, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

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

 Signature 

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

April 14, 2012

mlong mlong
Robot Herder
1551 posts

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

 Signature 

Senior Software Engineer
AccuWeather Enterprise Solutions
/* My views and opinions do not necessarily reflect those of my employer.  Void where prohibited. */

April 14, 2012

pascal95abc pascal95abc
Lab Rat
121 posts

Now I added linebreaks for optical reasons:

  1. Map {
  2.    id: map1;
  3.    plugin: Plugin { name: \"nokia\" }
  4.   anchors.fill: parent;
  5.   size.width: parent.width;
  6.   size.height: parent.height;
  7.   zoomLevel: 10; center:
  8.   Coordinate { latitude: 53.******; longitude: 8.****** }  
  9.   MapPolygon { id: polygon1; border { color: \"red\"; width: 4 }
  10.      Coordinate { latitude: 53.***; longitude: 8.*** }
  11.      Coordinate { latitude: 53.***; longitude: 8.*** }
  12.      Coordinate { latitude: 53.***; longitude: 8.*** }
  13.      Coordinate { latitude: 53.***; longitude: 8.*** }
  14.   }
  15. }

 Signature 

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

 
  ‹‹ [solved] Getting the last known position from GPS      QtQuick Desktop components ››

You must log in to post a reply. Not a member yet? Register here!