Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

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:

    @Map {
    id: map
    plugin : Plugin {
    name : "nokia"
    }
    anchors.fill: parent
    size.width: parent.width
    size.height: parent.height
    zoomLevel: t_data.zoomLevel
    center: Coordinate {latitude: 46.5; longitude: 6.6}//t_data.mapCenter

            onZoomLevelChanged: {
                console.log("Zoom changed")
            }
    
            MapCircle {
                 id: circle1
                 center: Coordinate {latitude: t_lati; longitude: t_lon} // {latitude: 46.5; longitude: 6.6}        
                 radius: t_data.radius
                 color: "yellow"
             }
    

    }@

    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



  • 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:

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

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



  • Hi Conny,

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

    Thank you!

    Juan



  • 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.



  • 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


Log in to reply