Results 1 to 1 of 1

Thread: google maps

  1. #1
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default google maps

    have looked everywhere and got no assistance. is it possible to embed Google earth into a qt application? I am very new to qt and visual C++ in general. I got a sample that connected to Google maps. It works fine except I am unable to pan the map. can you please assist me. I know solutions are never given without my showing that I have tried and failed. I do not even know where to start. the code I have is below:

    I basically want to to get on my desktop application what you get when you visit https://maps.google.com/
    Qt Code:
    1. #include <QWebFrame>
    2. #include <QWebPage>
    3. #include "GoogleMaps.h"
    4.  
    5. #define MAP_HTML \
    6. "<html>"\
    7. " <head>"\
    8. " <script type=\"text/javascript\""\
    9. " src=\"https://maps.google.com/maps/api/js?v=3.1&sensor=true\">"\
    10. " </script>"\
    11. " "\
    12. " <script type=\"text/javascript\">"\
    13. " var map; function init(lat, lng) {"\
    14. " var latLng = new google.maps.LatLng(lat, lng);"\
    15. " var myOptions = {"\
    16. " zoom: 18,"\
    17. " center: latLng,"\
    18. " mapTypeId: google.maps.MapTypeId.ROADMAP,"\
    19. " };"\
    20. " map = new google.maps.Map(document.getElementById(\"map_canvas\"),"\
    21. " myOptions);"\
    22. " var marker = new google.maps.Marker({"\
    23. " map: map,"\
    24. " position: myLatLng"\
    25. " });"\
    26. " }"\
    27. " </script>"\
    28. " "\
    29. " </head>"\
    30. ""\
    31. ""\
    32. "<body style=\"margin:0px; padding:0px;\" onload=\"init(-29.31418630,27.48326330);\">"\
    33. ""\
    34. " <div id=\"map_canvas\" style=\"width:100%; height:100%\">"\
    35. " </div>"\
    36. ""\
    37. "</body>"\
    38. ""\
    39. "</html>"\
    40.  
    41. class CWebPage : public QWebPage
    42. {
    43. virtual QString userAgentForUrl(const QUrl& url) const
    44. {
    45. Q_UNUSED(url);
    46.  
    47. //fix for dragging and zooming Google Maps.
    48. //It disables touch events so drag and zoom actions are handled by
    49. //Google Maps in a proper way.
    50. return "Chrome/1.0";
    51. }
    52. };
    53.  
    54. GoogleMapsViewer::GoogleMapsViewer(QWidget* parent)
    55. : QWebView(parent)
    56. {
    57. QString content = MAP_HTML;
    58.  
    59. CWebPage* page = new CWebPage();
    60. page->mainFrame()->setHtml(content);
    61. setPage(page);
    62. }
    To copy to clipboard, switch view to plain text mode 


    P.S
    I am using QT 4 on ubuntu 12.04
    Last edited by Liphoto; 7th May 2013 at 14:13.

Similar Threads

  1. QWebView, Google maps
    By Viper666 in forum Qt Programming
    Replies: 15
    Last Post: 20th October 2012, 14:45
  2. Google Earth/Maps and QWebView API
    By TheIndependentAquarius in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2012, 10:08
  3. how the Google maps get direction
    By MKSPulok in forum General Discussion
    Replies: 1
    Last Post: 16th June 2012, 22:52
  4. Google Maps API and QWebKit
    By QFreeCamellia in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2012, 06:42
  5. Map is not displayed from maps.google.com
    By abhilashajha in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 15:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.