2

I am having a QML code which shows map, it has a MapQuickItem for an image.

MapQuickItem {
    id: transMarker

    sourceItem: Image {
        id: transImage
        width: 50
        height: 50
        source: "trans.png"
    }
}

When I clicks on the map, it should paste that image on the map, I could achieve that by below code

transMarker.coordinate = map.toCoordinate(Qt.point(mouse.x,mouse.y))

I want to save the position permanently, but the problem is I am trying to print map.toCoordinate(Qt.point(mouse.x,mouse.y))

It prints in degree and minutes (Coordinate: 8° 29' 21.4" N, 76° 57' 41.9" E)

I want to get that as decimal latitude and longitude (Coordinate: 76.9616344 8.4892798).

How this can be accomplished?

NG_
  • 6,895
  • 7
  • 45
  • 67
ganeshredcobra
  • 1,881
  • 3
  • 28
  • 44

1 Answers1

5

You have to use the latitude and longitude properties of coordinate:

Map {
    id: map
    anchors.fill: parent
    plugin: Plugin {
        name: "osm"
    }
    center: QtPositioning.coordinate(59.91, 10.75)
    zoomLevel: 10

    MapQuickItem {
        id: transMarker
        sourceItem: Image {
            id: transImage
            width: 50
            height: 50
            source: "trans.png"
        }
    }
    MouseArea{
        anchors.fill: parent
        onClicked: {
            var coord = map.toCoordinate(Qt.point(mouse.x,mouse.y));
            transMarker.coordinate = coord;
            console.log(coord.latitude, coord.longitude)
        }
    }
}

Output:

qml: 59.969159320456804 10.824157714841107
qml: 59.98427615215763 10.895568847649372
qml: 59.989771470871446 10.780212402338407
qml: 59.965722714293186 10.652496337891108
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • How can i create a copy of image item "transImage" at corresponding latitude and longitude at each mouseclick on top of map. Now if i give transMarker.coordinate = transCoord, copy of image is not created image moves from one position to another. – ganeshredcobra Jul 08 '19 at 16:19