March 31, 2011

JuanF JuanF
Lab Rat
7 posts

How to change the value of QML Coordinate element at runtime?

 

Hi,

I am developing an application which requirs to display different contents on QML Map element. I asked one question yesterday how to add/remove map objects at runtime, and it is not yet solved. I tried to do a workaround, and now I have got another problem.

Is it possible to set the center of qml map or map object at runtime? The center of qml map and map object is a qml coordinate element.

Using the following qml:

  1. Map {
  2.             id: map
  3.             plugin : Plugin {
  4.                         name : "nokia"
  5.                     }
  6.             anchors.fill: parent
  7.             size.width: parent.width
  8.             size.height: parent.height
  9.             zoomLevel: t_data.zoomLevel
  10.             center: Coordinate {latitude: 46.5; longitude: 6.6}//t_data.mapCenter
  11.            
  12.             onZoomLevelChanged: {
  13.                 console.log("Zoom changed")
  14.             }
  15.  
  16.             MapCircle {
  17.                  id: circle1
  18.                  center: Coordinate {latitude: t_lati; longitude: t_lon} // {latitude: 46.5; longitude: 6.6}        
  19.                  radius: t_data.radius
  20.                  color: "yellow"
  21.              }
  22. }

The mapCircle can not be displayed if I set the value of latitude & longtitude from C++. However, map.zoomLevel, and mapcircle.radius can get the value from C++.

Did I do something wrong? How to control the value of QML Coordinate element from C++? I have checked the source code of QDeclarativeCoordinate and it has the latitude and longtitude as its properties, I don’t understand why I can’t expose data to it from C++?

Thank you very much!

Regards,
Juan

EDIT: added @ tag by vcsala

4 replies

March 31, 2011

conny conny
Lab Rat
85 posts

Hi!

First of all the QML bindings for location stuff are currently (Qt Mobility 1.1.1) in a very sorry state. I’ve heard it should get better with QtM 1.2. I’m currently working around this by doing most map related things using C++.

For your particular problem, I remember a snipped I used before moving to C++. Something like this worked for me:

  1.     function setPosition(lat, lon) {
  2.         var coord = Qt.createQmlObject('import QtMobility.location 1.1; Coordinate{latitude:' + lat + ';longitude:' + lon + ';}', container, "coord");
  3.         map.center = coord;
  4.     }

This basically creates a new Coordinate object and sets it as center.

April 1, 2011

JuanF JuanF
Lab Rat
7 posts

Hi Conny,

I decide to move to the C++ side on map related issues as well… :-)

Thank you!

Juan

April 4, 2011

david.laing david.laing
Lab Rat
65 posts

Out of curiosity, are t_lati and t_lon defined anywhere? Without more information it’s a) hard to help out and b) hard to check if this is fixed or needs fixing for the next release.

I don’t have any trouble modifying the center coordinate of circles from the QML side with the code in the master branch of git.

 Signature 

David Laing
Location API team
Qt Mobility

April 4, 2011

JuanF JuanF
Lab Rat
7 posts

Hi,

I use the Qt SDK 1.1 beta, not the sdk from MCL.

I am now using the map widget from C++, but I will test how QML location plugin works when the 1.2 release is out.

Thank you!

Juan

 
  ‹‹ Width of ListView is -1      "Chained" transitions? ››

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