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

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

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.java

This is the code I’m using:git

 

  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?web

相關文章
相關標籤/搜索