Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Current Location on map in Android
QtWS25 Last Chance

Current Location on map in Android

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 65 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msauer751
    wrote on 25 Jan 2025, 16:06 last edited by
    #1

    Hi,

    I want to display the current location in my Map element on android. I have the following code:

            Map {
                id: map
                property geoCoordinate startCentroid
                Component.onCompleted: {
                    console.log("x="+width+", y="+height)
                }
                anchors {
                    top: headerBox.bottom
                    topMargin: 15
                    left: parent.left
                    right: parent.right
                    bottom: parent.bottom
                    leftMargin: Style.sizeScreenMargin
                    rightMargin: Style.sizeScreenMargin
                    bottomMargin: Style.sizeScreenMargin
                }
                plugin: Plugin {
                    id: myPlugin
                    name: "osm"
                    PluginParameter {name: "osm.mapping.providersrepository.address"; value: Qt.resolvedUrl("qrc:/providers")}
                    PluginParameter { name: "osm.mapping.highdpi_tiles"; value: true }
                }
                zoomLevel: 7
                center: QtPositioning.coordinate(49.843056, 9.901944)       // Mittelpunkt Bayern
                activeMapType: map.supportedMapTypes[6] // Hiking map provided by Thunderforest
    
                PinchHandler {
                    id: pinch
                    target: null
                    onActiveChanged: if (active) {
                        map.startCentroid = map.toCoordinate(pinch.centroid.position, false)
                    }
                    onScaleChanged: (delta) => {
                        map.zoomLevel += Math.log2(delta)
                        map.alignCoordinateToPoint(map.startCentroid, pinch.centroid.position)
                    }
                    //grabPermissions: PointerHandler.TakeOverForbidden
                }
    
                WheelHandler {
                    id: wheel
                    // workaround for QTBUG-87646 / QTBUG-112394 / QTBUG-112432:
                    // Magic Mouse pretends to be a trackpad but doesn't work with PinchHandler
                    // and we don't yet distinguish mice and trackpads on Wayland either
                    acceptedDevices: Qt.platform.pluginName === "cocoa" || Qt.platform.pluginName === "wayland"
                                     ? PointerDevice.Mouse | PointerDevice.TouchPad
                                     : PointerDevice.Mouse
                    rotationScale: 1/120
                    property: "zoomLevel"
                }
                DragHandler {
                    id: drag
                    target: map
                    onTranslationChanged: (delta) => map.pan(-delta.x, -delta.y)
                }
                Shortcut {
                    enabled: map.zoomLevel < map.maximumZoomLevel
                    sequence: StandardKey.ZoomIn
                    onActivated: map.zoomLevel = Math.round(map.zoomLevel + 1)
                }
                Shortcut {
                    enabled: map.zoomLevel > map.minimumZoomLevel
                    sequence: StandardKey.ZoomOut
                    onActivated: map.zoomLevel = Math.round(map.zoomLevel - 1)
                }
    
                MapItemView {
                    id: cacheKoordWm
                    model:  masterController.uiSpListe.uiItems ? masterController.uiSpListe.uiItems : 0
                    delegate: MapQuickItem {
                        coordinate: QtPositioning.coordinate(modelData.uiKoordLat, modelData.uiKoordLon)
                        sourceItem: Column {
                            Rectangle {
                                id: circWm
                                width: Style.widthCircle
                                height: Style.widthCircle
                                radius: width*0.5
                                color: "#f8e81c"
                                border.color: "#000000"
                                border.width: 1
                                MouseArea {
                                    id: mouseWm
                                    hoverEnabled: true
                                    anchors.fill:parent
                                    onClicked: function(mouse) {
                                        hoverEnabled: true
                                        if (mouse.button == Qt.LeftButton) {
                                            masterController.uiSp.uiSpCodeSearch.uiValue = modelData.uiSpCode
                                            spCodeClicked()
                                        }
                                    }
                                    onEntered: {
                                        ttWm.open()
                                    }
                                    onExited: {
                                        ttWm.close()
                                    }
                                    ToolTip {
                                        id:ttWm
                                        text: modelData.uiSpName
                                    }
                                }
                            }
                        }
                    }
                }
            }
    
            LocationPermission {
                id: permission
                accuracy: LocationPermission.Precise
                availability: LocationPermission.WhenInUse
            }
    
            Dialog {
                id: permissionDialog
                anchors.centerIn: parent
                padding: 20
                standardButtons: (permission.status === Qt.Denied) ? Dialog.Close
                                                                   : Dialog.Close | Dialog.Ok
                closePolicy: Dialog.NoAutoClose
                title: qsTr("Permission")
    
                Label {
                    id: permissionRequestText
                    text: (permission.status === Qt.Denied)
                          ? qsTr("Grant the location permission then open the app again.")
                          : qsTr("Location permission is needed.")
                }
    
                onAccepted: {
                    if (permission.status !== Qt.Denied)
                        permission.request();
                }
    
                onStandardButtonsChanged: {
                    if (standardButtons & Dialog.Ok)
                        standardButton(Dialog.Ok).text = qsTr("Request Permission");
                }
    
                Component.onCompleted: {
                    if (permission.status !== Qt.Granted)
                        open();
                }
            }
    

    On Android I will get the permissions dialog. I accept the location access, but I don't get the current location on the map. What can I do to add a point with the current loccation on the map?

    Thank you for your help.
    BR
    martin

    1 Reply Last reply
    0

    1/1

    25 Jan 2025, 16:06

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved