How to add Google Maps in my application in Qt?

前端 未结 6 1358
耶瑟儿~
耶瑟儿~ 2020-12-24 00:18

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 Q

相关标签:
6条回答
  • 2020-12-24 00:57

    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.

    0 讨论(0)
  • 2020-12-24 01:04
        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

    0 讨论(0)
  • 2020-12-24 01:09

    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:

    • How to clone from git and how to compile the code
    • The code itself

    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.

    0 讨论(0)
  • 2020-12-24 01:12

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

    0 讨论(0)
  • 2020-12-24 01:18

    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.

    0 讨论(0)
  • 2020-12-24 01:20

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

    • QML & Qt Google Maps: http://code.google.com/p/qt-google-maps/wiki/About

      API features used in this project:

      • Create and tuning map
      • Create placemarks (markers)
      • Goto placemark
    • Qt Google Places: http://code.google.com/p/qt-google-places/wiki/About

      API features used in this project:

      • Create and tuning map
      • Autocomplete search address
      • Get coordinates by address
      • Search places by name, type and location
      • Get place details
      • Add new user place
      • Delete user place
      • Add new event
      • Delete event
    • QML & Qt Google Latitude: http://code.google.com/p/qt-google-latitude/wiki/About

      API features used in this project:

      • Create and tuning map
      • Create placemarks (markers)
      • Get current location
      • Insert current location
      • Get history of location
      • Insert to history of location
      • Goto address
    0 讨论(0)
提交回复
热议问题