Using Google Maps in an native mobile application
-
Hey Guys!
I want to use Google Maps in an native mobile application under Qt 5.7. Has anybody experiences and even better, has anybody a kind of example how I can do this in Qt 5.7? Thanks for any help!
Greetings, Simon
[Moved to Mobile and Embedded ~kshegunov]
-
Hey Guys!
I want to use Google Maps in an native mobile application under Qt 5.7. Has anybody experiences and even better, has anybody a kind of example how I can do this in Qt 5.7? Thanks for any help!
Greetings, Simon
[Moved to Mobile and Embedded ~kshegunov]
Hi,
You can use theQtLocation
module (there's examples in the docs) and switch the provider plugin to one supporting google maps (there's a user contributed plugin for google maps https://github.com/vladest/googlemaps). You'll need to compile the plugin, but aside from that I have tested it and it works.Kind regards.
-
Hi,
You have to build and install the plugin first:
qmake make make install
Then you can follow the example @kshegunov linked in his answer and change the selected plugin to use the one you just installed.
-
What OS are you developing on ?
-
Visual Studio or MinGW ?
-
Then replace
make
withnmake
-
Hi everyone!
First thanks for all advices, very helpful. The plugin is installed.
Now I am facing the problem that I want to integrate Google Maps into the qml code with the help of the QtLocation module.
Do you have any kind of a minimal code example?@kshegunov
What do you mean by "switch the provider plugin to one supporting google maps"?Kind regards.
-
Hi everyone!
First thanks for all advices, very helpful. The plugin is installed.
Now I am facing the problem that I want to integrate Google Maps into the qml code with the help of the QtLocation module.
Do you have any kind of a minimal code example?@kshegunov
What do you mean by "switch the provider plugin to one supporting google maps"?Kind regards.
I mean that after you download and compile one of the
QtLocation
examples, you open the QML file find where the plugin is specified and change the name, thus you load another plugin that provide maps. -
Now, for all who wants to integrate Google Maps in their application, here is a summary with a minimal code example.
Tested system environment: Windows 10, Qt 5.7, Visual Studio Compiler.-
Install the following plugin: https://github.com/vladest/googlemaps by calling the
qmake
,nmake
andnmake install
via cmdIf struggling with compiling the plugin in cmd regarding the error x86/x64, use the compiler of a real 64bit compiler of Visual Studio (not the Express version of Visual Studio) and call the vcvarsall.bat file with the parameter x64 first.
-
Using the following qml code to call the map in your qt application.
Plugin { id: myPlugin name: "googlemaps" PluginParameter { name: "googlemaps"; value: "http://maps.googleapis.com/maps/api/js?sensor=false" } } Map { anchors.fill: parent plugin: myPlugin zoomLevel: 0 Component.onCompleted: { for( var i_type in supportedMapTypes ) { print (supportedMapTypes[i_type].name) if( supportedMapTypes[i_type].name.localeCompare( "Custom URL Map" ) === 0 ) { activeMapType = supportedMapTypes[i_type] } } } }
Good luck! =)
-
-
-
Hi,
With which version of Qt are you building that plugin ?
-
Hey, that was fast and a good hint, thank you :) My standard qmake was the wrong version. Qmake from Qt 5.8 works, but make (g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4) throws directly the next errors:
g++: error: unrecognized command line option ‘-std=c++1z’ g++: error: unrecognized command line option ‘-Wdate-time’
For the first one I found this Qt bug-report: https://bugreports.qt.io/browse/QTBUG-51644, for the second one this: https://bugreports.qt.io/browse/QTBUG-53017, but it seems like both should be fixed Qt 5.6...
I'm not sure if this a Qt-related problem anymore, but any ideas? I can barely find anything about those on Google.
-
For a quick solution you can edit the
qt_common.prf
and modify the logic selecting the date-time warning. As for the std switch IIRC you can use something likeCONFIG += c++14
. -
For a quick solution you can edit the
qt_common.prf
and modify the logic selecting the date-time warning. As for the std switch IIRC you can use something likeCONFIG += c++14
.@SGaist Hi,
I edited the mkspecs/features/qt_common.prf and commented out the warning for the Wdate-time. Also I edited the mkspecs/common/q++-base.conf and replaced every "1z" with "11" (found this suggestion somewhere else, because your CONFIG =+ c++14 seemed not to work). I have to be honest, I don't know exactly what the error was and what I did to fix it, but it works now :D Thank you for your help :)
-
You changed the standard used to compile your application. 1z is the equivalent of C++17 IIRC.