Naufal
Naufal

Reputation: 325

How to add Google Maps in my application in Qt?

I am developing an application where I am in need of adding the Google map into our application. I am using Qt with UI design and I am not using QML. Is there any API for Qt for symbian or any file to be added to port into my app?

Upvotes: 19

Views: 46541

Answers (7)

Khalil Hermassi
Khalil Hermassi

Reputation: 29

QT does not support QWebView anymore unfortunately !

Upvotes: 0

Aquarius_Girl
Aquarius_Girl

Reputation: 22916

-Qt API for Google Maps-
From: https://www.ics.com/technologies/qt/qt-based-clients-google-apis

Upvotes: 9

Wim
Wim

Reputation: 547

Using QWebView might probably work, but I have no idea if then interaction can take place between Google Maps and your own code.

My project is based on the code of qt-google-maps. You can still find it at the Google Code Archive:

I remember that I had to change a little bit because the code was based on version 2 of the Google Maps API, and now only version 3 was supported. But even that was quite easy. I see that the "new" code now incorporates version 3 as well.

On GitHub I also found a project that uses the code, but made a QT5-version of it and it has been active until one year ago, so probably you have more chances to find working code there.

On my personal GitHub, I decided to continue using QT4 and the interaction with Google Maps is running pretty ok. Here is the latest version, but the code is probably a bit messy and incomprehensible due to lack of time to work on it in more depth (sorry for that), so best to start from this commit. It has the basic version of qt-google-maps from 2012, updated by me for Google Maps APIv3 (so there will be some differences with the first link that I posted here), and not too much of my personal code in it.

Make sure you read the compile instructions.

Upvotes: 1

Vincas Dargis
Vincas Dargis

Reputation: 555

If you could use other map providers, there is now QtLocation module (currently Technical Previw as of time of writing for Qt 5.5) which can render HERE, Mapbox and OpenStreetMap maps, and also you can create your own plugin for other providers.

Though sadly, Google Maps is not supported, and looks like it's not going to happen at all due to Google Maps Terms & Conditions.

Upvotes: 0

Frexus
Frexus

Reputation: 150

I've been working on my university project in Qt using Google Maps as the main widget. Basically, it's best to load an external HTML file into QWebView which contains javascript code necessary to load the map. This practice lets you define javascript functions inside HTML file that can control the map (markers, etc) which you can then easily call in your Qt code. There is one catch though. When you load the map into your QWebView widget you will not be able to interact with it at all. To get rid of this problem you will need to create a class that inherits QWebPage that fakes user agent, for example:

class myWebPage : virtual public QWebPage
{
    virtual QString userAgentForUrl(const QUrl& url) const
    {
        return "Chrome/1.0";
    }
};

You will need to create a class that inherits QWebView and set this class' main page to new instance of the class myWebPage. Next step is to add a QWebView widget in your Designer. Promote this widget to your custom QWebView class. You will then have a fully functional map.

Upvotes: 2

Rodrigo
Rodrigo

Reputation: 321

I have a very small project (https://github.com/skhaz/qtgps) that uses Google Maps in a qwebview and some javascript to interact

Upvotes: 0

Lwin Htoo Ko
Lwin Htoo Ko

Reputation: 2406

    QWebView *webView = new QWebView(parentWidget);
    webView->resize(1000,500);
    webView->move(10,10);
    QString gMapURL = "England"; // this is where you want to point
    gMapURL = "http://maps.google.com.sg/maps?q="+gMapURL+"&oe=utf-8&rls=org.mozilla:en-US:official&client=firefox-a&um=1&ie=UTF-8&hl=en&sa=N&tab=wl";
    webView->setUrl(QUrl(gMapURL));

This is a kind of cheap way of getting google map in Qt. Maybe, there is some smarter way of getting it using Google Maps API Web Services. http://code.google.com/apis/maps/documentation/webservices/index.html

Upvotes: 3

Related Questions