Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QtLocation:如何在地图上进行拖放?_Qt_Drag And Drop_Qml_Qtlocation - Fatal编程技术网

QtLocation:如何在地图上进行拖放?

QtLocation:如何在地图上进行拖放?,qt,drag-and-drop,qml,qtlocation,Qt,Drag And Drop,Qml,Qtlocation,我有一个QMLMapwidget。我想在上面放置一些物体,以获得放置点的纬度和经度。我该怎么做呢?您可以像所有其他拖放应用程序一样进行操作。在Qt文档中以及在互联网上都有大量的例子。 其中一项: import QtQuick 2.9 import QtQuick.Window 2.0 import QtLocation 5.3 Window { id: window width: 600 height: 400 visible: true MouseA

我有一个QML
Map
widget。我想在上面放置一些物体,以获得放置点的纬度和经度。我该怎么做呢?

您可以像所有其他拖放应用程序一样进行操作。在Qt文档中以及在互联网上都有大量的例子。 其中一项:

import QtQuick 2.9
import QtQuick.Window 2.0
import QtLocation 5.3

Window {
    id: window
    width: 600
    height: 400
    visible: true

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        drag.target: item
        propagateComposedEvents: true
        onReleased: item.Drag.drop()
    }

    Plugin {
        id: mapPlugin
        preferred: ["osm", "esri"]
    }

    Map {
        id: map
        anchors.fill: parent
        anchors.topMargin: 40
        anchors.bottomMargin: 30
        plugin: mapPlugin
        center {
            latitude: 40.785091
            longitude: -73.968285
        }
        zoomLevel: 14
        DropArea {
            anchors.fill: parent
            onDropped: {
                var coord = map.toCoordinate(Qt.point(drop.x, drop.y));
                output.text = "latitude:" + coord.latitude + ", longitude:" + coord.longitude;
                anim.running = true;
            }
        }
    }

    Rectangle {
        id: item
        x: parent.width/2 - 20
        y: 0
        width: 40
        height: 40
        radius: 20
        color: "orange"
        opacity: 1
        Drag.active: mouseArea.drag.active
        Drag.hotSpot.x: 20
        Drag.hotSpot.y: 20

        Text {
            anchors.centerIn: parent
            text: "Drop me"
            font.pixelSize: 8
        }

        SequentialAnimation {
            id: anim
            running: false
            NumberAnimation { target: item; property: "opacity"; to: 0; duration: 500 }
            PropertyAction { target: item; property: "x"; value: window.width/2 - 20 }
            PropertyAction { target: item; property: "y"; value: 0 }
            NumberAnimation { target: item; property: "opacity"; to: 1; duration: 500 }
        }
    }

    Text {
        id: output
        anchors.bottom: parent.bottom
        height: 30
        width: window.width
        text:  ""
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.AlignHCenter
    }
}