QML-maps:点击屏幕时获取坐标

时间:2016-01-06 15:46:48

标签: android c++ qt maps qml

我正在使用Qt Creator(社区)5.5.1制作项目并支持QML。 我有这段代码:

main.qml:

MouseArea
        {   anchors.fill: parent
            onPressed: console.log('latitude = '+ (map.toCoordinate(Qt.point(mouse.x,mouse.y)).latitude),
                                   'longitude = '+ (map.toCoordinate(Qt.point(mouse.x,mouse.y)).longitude));

所以当我点击屏幕时,地图上这个地方的坐标会显示在控制台上。但我不知道如何使用这些坐标将标记定位在点击发生的屏幕上。这是标记代码:

MapQuickItem {
        id:marker
        coordinate:  QtPositioning.coordinate(******, ******);//stars are the coordinates
        sourceItem: Image{
            id: image
            source: "marker2.png"

        }
        anchorPoint.x: image.width / 2
        anchorPoint.y: image.height

    }

如何将标记放置在点击发生的坐标上的地图上?感谢。

1 个答案:

答案 0 :(得分:4)

只需在coordinate处理程序中设置marker的{​​{1}}即可。如下所示:

onPressed