Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project

Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project

Qt WebKit and HTML5 geolocation

 

I’m learning HTML5 and testing the new features on a Qt hybrid application.
Now I’m working on a simple geolocation example but when I call navigator.geolocation.getCurrentPosition(displayLocation); it seems the QtWebKit does not support it, but acording to this http://trac.webkit.org/wiki/QtWebKitFeatures22 the version of QtWebKit that comes with Qt4.8.0 supports geolocation.

This is the code I’m using:

 

  1. window.onload = function()
  2. {
  3.     getMyLocation();      
  4. }
  5.  
  6. function getMyLocation()
  7. {
  8.     if(navigator.geolocation)
  9.     {
  10.         navigator.geolocation.getCurrentPosition(displayLocation);        
  11.     }  
  12.     else
  13.     {
  14.         alert("No geolocation support");  
  15.     }
  16. }
  17.  
  18. function displayLocation(position)
  19. {
  20.     var latitude = position.coords.latitude;
  21.     var longitude = position.coords.longitude;
  22.    
  23.     var div = document.getElementById("location");
  24.    
  25.     div[removed] = "You are at Latitude: " + latitude + ", Longitude: " + longitude;  
  26. }

 

 

  1. QWebView* MyWindow::createWebView()
  2.     {
  3.         QWebSettings* default_settings = QWebSettings::globalSettings();
  4.         default_settings->setAttribute(QWebSettings::JavascriptEnabled,true);
  5.         default_settings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled,true);
  6.         default_settings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled,true);
  7.         default_settings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls,true);        
  8.         default_settings->setAttribute(QWebSettings::LocalStorageEnabled,true);
  9.         default_settings->setAttribute(QWebSettings::JavascriptCanAccessClipboard,true);
  10.         default_settings->setAttribute(QWebSettings::DeveloperExtrasEnabled,true);
  11.  
  12.         QWebView* web_view = new QWebView(this);
  13.  
  14.         connect(web_view->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
  15.                 this, SLOT(addJavascriptObject()));
  16.  
  17.         inspector_->setPage(web_view->page());
  18.  
  19.         inspector_->setVisible(true);
  20.         inspector_->show();
  21.  
  22.         web_view->load(QUrl("qrc:/html/geolocation_example.html"));
  23.        
  24.         return web_view;
  25.     }

 

Anyone knows how to enable geolocation for a desktop app?

Qt WebKit and HTML5 geolocation | Qt Project forums | Qt Project,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。