Adding objects to the “Map” with addMapObject
-
Hello.
Always when I try to add an object to the map (exactly following "this explanation":http://doc.qt.nokia.com/qtmobility/qml-map.html#addMapObject-method) I get this error message:
TypeError: Result of expression 'map.addMapObject' [undefined] is not a function.Hope someone can help.
-
Can you provide the pertinent part of your code where you define map and where you're trying to use addMapObject, please?
-
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: parentMapPolygon { 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 } }@
-
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. -
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. -
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) -
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!!! -
I merged these two threads because they are so closely-related.
-
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...
-
bq. This is one single line.
Any particular reason?
-
This was just for information, because then you know there are no strange break within a word or a command.
-
Would be easier to read if it were indented properly, etc.
-
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. }
}
}
@