google maps in qt



  • what is the best way to use google maps in qt c++ preferably or qml ?



  • Hi,

    You can use the Google Api that had already been provided.

    reference:
    https://developers.google.com/maps/web-services/overview#find-out-which-api-you-need


  • Moderators

    Hi! If you're fine with OpenStreetMap instead of Google Maps then you can use Maps and Navigation (QML).


  • Lifetime Qt Champion

    Hi,

    There's also a forum member that has implemented a backend for it. See this thread



  • @SGaist

    Hi I found this googlemaps plugin link in the thread you sent. As I am quiet new to Qt, could you give some hint on how to use this plugin along with Qtlocation C++.


  • Moderators

    @saitej Don't know what you want to do, just as a reminder: "Currently it is not possible to interact with maps via C++".



  • @Wieland
    Hi ..
    I want to display the current location as the first step using the googlemaps plugin either in qml or c++ which ever is possible.


  • Moderators

    @saitej You can't do this in C++ but QtQuick comes with the easy to use Map type.



  • @Wieland

    I tried the code from the link you had sent but am unable to view any map.
    This is my main.qml code. The code doesn’t give an error but displays a blank window.

    import QtPositioning 5.5
    import QtLocation 5.6
    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 400
        height: 600
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                Qt.quit();
            }
        }
        Plugin{
            id:myplugin
            name: "osm"
        }
        Map {
            id: map
            plugin: myplugin
            center {
                latitude: -27
                longitude: 153
            }
            zoomLevel: map.minimumZoomLevel
    
            gesture.enabled: true
        }
    
    
    }
    
    
    
    
    


  • In my case, I used the API QMapControl Under LGPL license.
    It's very easy to use.


  • Moderators

    @saitej Add anchors.fill: contentItem to your Map item ;-)



  • Hi
    I am having few basic issues with this code. I am unable to display the marker on the map.
    Also, where do I write the signal showRoute(startCoordinate,endCoordinate)
    It's giving me already declared error

    I am used to c++ and I just started to use qml. so the doubts will be pretty basic so please bear with me

    import QtPositioning 5.5
    import QtLocation 5.6
    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    import QtQuick.Layouts 1.3
    
    Window {
        visible: true
        width: 400
        height: 600
    
        MouseArea {
            anchors.fill: parent
            //        onClicked: {
            //            Qt.quit();
            //        }
        }
    
        //    splitview
    
        SplitView {
            anchors.fill: parent
            orientation: Qt.Vertical
            //rect1
            Rectangle {
                height: 150
                Layout.maximumHeight:  200
                //               color: "lightblue"
    
                Label {
                    id: label1
                    text: "Latitude Start"
                    x:0
                    y:2
    
                }
                Label{
                    id : label2
                    text: "Longitude Start"
                    x:0
                    y:25
                }
    
                Label {
                    id: label3
                    text: "Latitude End"
                    x:0
                    y:50
    
                }
                Label{
                    id : label4
                    text: "Longitude End"
                    x:0
                    y:75
                }
                //            textinputs
                TextInput {
                    //                anchors.fill:
                    id: input1
                    x:150
                    y:2
                    font.pixelSize: 12; font.bold: false
                    cursorVisible: true
                    text:  "12.9716"
                    //                acceptableInput:
                    validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ }
                    focus:true
                }
                TextInput {
                    //                anchors.fill: contentItem
                    id: input2
                    x:150
                    y:25
                    font.pixelSize: 12; font.bold: false
                    //                acceptableInput:
                    validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ }
                    //                focus:true
                    echoMode: TextInput.Normal
                    activeFocusOnTab: true
                    text: "77.5946"
                }
    
                TextInput {
                    //                anchors.fill: contentItem
                    id: input3
                    x:150
                    y:50
                    font.pixelSize: 12; font.bold: false
                    //                acceptableInput:
                    validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ }
                    //                focus:true
                    echoMode: TextInput.Normal
                    activeFocusOnTab: true
                    text: "19.0760"
    
                }
    
    
                TextInput {
                    //                anchors.fill: contentItem
                    id: input4
                    x:150
                    y:75
                    font.pixelSize: 12; font.bold: false
                    //                acceptableInput:
                    validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ }
                    //                focus:true
                    echoMode: TextInput.Normal
                    activeFocusOnTab: true
                    text: "72.8777"
    
                }
    
                Button{
                    id:goButton
                    text : "GO!"
                    anchors.horizontalCenter: parent.horizontalCenter
                    y: 100
                    onClicked: {
                        var startCoordinate = QtPositioning.coordinate(parseFloat(input1.text),
                                                                       parseFloat(input2.text));
                        var endCoordinate = QtPositioning.coordinate(parseFloat(input3.text),
                                                                     parseFloat(input4.text));
                        if (startCoordinate.isValid && endCoordinate.isValid) {
    
                            goButton.enabled = false;
                            showRoute(startCoordinate,endCoordinate)
                        }
    
                    }
    
                }
                Plugin{
                    id:myplugin
                    name: "osm"
                }
    
    
    
    
    
            } //rectangle ends here
    
    
    
    
            Map {
                id: map
                plugin: myplugin
                center {
    
                    //                latitude: 12.9716 //
                    //                longitude: 77.5946 //
                    latitude :input1.text
                    longitude:input2.text
    
                }
                zoomLevel: 13
                anchors.fill: contentItem
                gesture.enabled: true
                //            property variant location: QtPositioning.coordinate( input1.text, input2.text)
                MapItemView {
                    model:PlaceSearchModel
                    delegate: MapQuickItem {
                        id : marker
                        coordinate: QtPositioning.coordinate( input1.text, input2.text)
    
                        anchorPoint.x: image.width * 0.5
                        anchorPoint.y: image.height
                        sourceItem: Image {
                            id: image
                            source: "qrc:/marker.png"
    
                        }
    
                    }
    
                }
    
            }
    
    
        }
    
    
    }
    
    
    
    
    


  • @saitej
    anybody can to used google map api in QML
    and used navigation and traffic from google map api ?



  • QWebView::load


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.