11

Attempting to get the GPS coordinates in a HTML5 web page viewed with Necessitas's port of QWebView. However it always responds with Not Supported.

function load( )
{
   if ( navigator.geolocation )
   {
      alert( "Supported." );
   }
   else
   {
      alert( "Not Supported!" );
   }
}

I've altered the QWebPage to allow permissions:

BrowserWebPage::BrowserWebPage( QObject* parent ) : QWebPage( parent )
{
    connect( this,
             SIGNAL( featurePermissionRequested( QWebFrame*, QWebPage::Feature ) ),
             SLOT( permissionRequested( QWebFrame*, QWebPage::Feature ) ) );
}

void BrowserWebPage::permissionRequested( QWebFrame* frame, QWebPage::Feature feature )
{
    if ( feature == Geolocation )
    {
        setFeaturePermission( frame, feature, PermissionGrantedByUser );
    }
    else //denied
    {
        setFeaturePermission( frame, feature, PermissionDeniedByUser );
    }
}

And set the following permissions:

android.permission.INTERNET

android.permission.ACCESS_FINE_LOCATION

android.permission.ACCESS_COARSE_LOCATION

EDIT

According to this page the GeoLocation API is present within the QtWebKit build.

http://trac.webkit.org/wiki/QtWebKitFeatures22

DETAILS

Phone: Galaxy Nexus

Platform: Android 4.1.1 (SDK 14)

Framework: Qt 4.8.0 for Android armv7a

Ben Crowhurst
  • 8,204
  • 6
  • 48
  • 78
  • 1
    I think `android.permission.FINE_LOCATION` should be `android.permission.ACCESS_FINE_LOCATION`. Also, have you seen this [answer](http://stackoverflow.com/a/5423026/624093)? It seems to have some good tips (not Qt-specific, but may still help). – rexmac Sep 21 '12 at 13:47

2 Answers2

1

I think you will have to set coarse location and internet permission because the fine location is only used for gps if im right. in any case having both is good cause if gps is not available the location over your internet connection will be used.

   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
   <uses-permission android:name="android.permission.INTERNET" /> 

I don't really have experience with qtwebkit but this is the basics i can tell you.

SunnySonic
  • 1,318
  • 11
  • 37
  • Thanks for your time. However this has already been attempted with no luck. – Ben Crowhurst Sep 25 '12 at 08:19
  • Have a look at this http://www.developer.nokia.com/Community/Discussion/showthread.php?224847-QtWebkit-and-javascript-navigator.geolocation.getCurrentPosition – SunnySonic Sep 25 '12 at 08:26
1

I just tried something very similar and couldn't get navigator.geolocation to work so I implemented a my own geolocation class and added it to the frame.

mygeolocation object implemented a signal and a slot

signal:
void updatepos(float lon, float lat); // called from get location when location is found

slot:
void getlocation(); // gets location and calls updatepos

after page had loaded:

frame->addToJavaScriptWindowObject(QString("geo"), geo);
frame->evaluateJavaScript("init()");

Where geo was instance of my geolocation object

In javascript I connected my geo object signal update to a function,

function update(lon,lat)
{
// do stuff with lon, lat
}

function init(){
   geo.connect(update); // connect to QT code
   geo.getlocation(); // ask for update from QT code
}

This is bit pseudo coding - I don't have the original code available at the moment.

CodeBro
  • 209
  • 1
  • 4