Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Android平台上的QWebView HTML5地理定位_Javascript_Android_C++_Html_Qt4 - Fatal编程技术网

Javascript Android平台上的QWebView HTML5地理定位

Javascript Android平台上的QWebView HTML5地理定位,javascript,android,c++,html,qt4,Javascript,Android,C++,Html,Qt4,试图在使用Essentials的QWebView端口查看的HTML5网页中获取GPS坐标。但是,它总是以“不支持”作为响应 function load( ) { if ( navigator.geolocation ) { alert( "Supported." ); } else { alert( "Not Supported!" ); } } 我已更改QWeb页面以允许权限: BrowserWebPage::BrowserWebP

试图在使用Essentials的QWebView端口查看的HTML5网页中获取GPS坐标。但是,它总是以“不支持”作为响应

function load( )
{
   if ( navigator.geolocation )
   {
      alert( "Supported." );
   }
   else
   {
      alert( "Not Supported!" );
   }
}
我已更改QWeb页面以允许权限:

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 );
    }
}
并设置以下权限:

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 );
    }
}
android.permission.INTERNET

android.permission.ACCESS\u FINE\u位置

android.permission.ACCESS\u位置

编辑

根据此页面,地理定位API存在于QtWebKit构建中

详细信息

电话:Galaxy Nexus

平台:Android 4.1.1(SDK 14)


框架:适用于Android armv7a的Qt 4.8.0

我认为您必须设置粗略位置和互联网权限,因为只有在im正确的情况下,精细位置才用于gps。在任何情况下,如果gps不可用,将使用internet连接上的位置,两者都是很好的理由

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


我没有使用qtwebkit的经验,但这是我可以告诉你的基本知识。

我只是尝试了一些非常类似的方法,但无法使navigator.geolocation正常工作,所以我实现了一个我自己的geolocation类并将其添加到框架中

mygeolocation对象实现了一个信号和一个插槽

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

slot:
void getlocation(); // gets location and calls updatepos
页面加载后:

frame->addToJavaScriptWindowObject(QString("geo"), geo);
frame->evaluateJavaScript("init()");
其中geo是我的geolocation对象的实例

在javascript中,我将geo对象信号更新连接到一个函数

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
}

这是位伪编码-我目前没有可用的原始代码。

我认为
android.permission.FINE\u LOCATION
应该是
android.permission.ACCESS\u FINE\u LOCATION
。还有,你看到这个了吗?它似乎有一些很好的提示(不是Qt特定的,但可能仍然有帮助)。谢谢您的时间。然而,这一尝试已经失败了。看看这个