Sal*_*lvo 1 qt qml here-api qtlocation here-maps-rest
我正在努力在 HERE 插件中进行身份验证。我使用的是带有 Qt 5.9.1 Mingw 32bit 的 Windows 10,我的应用程序几乎都是用 C++ 编写的。我使用 QML 的唯一部分是关于地图。我想使用 HERE 插件,但我是 QtLocation 和插件的新手,我真的不明白我需要做什么才能在 HERE 中进行身份验证。我试图按照 HERE 网站上的指南进行操作,但我真的无法理解。
我从 qt 知道我必须用来验证 HERE 的代码如下:
Plugin {
name: "here"
PluginParameter { name: "here.app_id"; value: "myapp" }
PluginParameter { name: "here.token"; value: "abcdefg12345" }
}
Run Code Online (Sandbox Code Playgroud)
所以我需要here.app_id和here.token。
我在 HERE 站点上创建了一个帐户,并使用 REST 创建了一个项目。所以现在我有了我的APP ID参数,但我真的不明白如何将TOKEN值放入第二行。首先,对于我的具体情况,我需要创建一个 api 密钥还是一个 OAuth 2.0?
我尝试使用 Postman遵循此链接中所写的内容,最后我得到了一个非常长的tokoen,我将其复制并放入“here.token”参数中,但是当我运行该应用程序时,它给了我Invalid here.token和它不显示地图。
有人可以给我任何有关如何正确获取令牌值的提示吗?或者有人可以指点我一些链接吗?例如,是否有不同的方式使用 api 密钥而不是令牌登录?
- - - - - - - - 更新 - - - - - - - - - - - - - - - - - ------
过了一段时间我不得不回到这个我从未解决过的问题上:现在的情况是我设法通过邮递员获得了令牌,但它总是无效的。现在我正在使用 Qt 5.15.2 和 MinGw 64 位。
我正在使用修改后的 minimum_map 示例以添加 here.app_id 和 here.token 参数。
主文件
import QtQuick 2.15
import QtQuick.Window 2.15
import QtLocation 5.6
import QtPositioning 5.6
Window {
width: Qt.platform.os == "android" ? Screen.width : 512
height: Qt.platform.os == "android" ? Screen.height : 512
visible: true
Plugin {
id: mapPlugin
name: "here" // "mapboxgl", "esri", ...
// specify plugin parameters if necessary
parameters: [
PluginParameter {
name: "here.app_id"
value: "xxxxx"
},
PluginParameter {
name: "here.token"
value: "yyyyyy"
}]
}
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当我运行应用程序时,输出如下:
Invalid here.token
3 , "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."
Run Code Online (Sandbox Code Playgroud)
为了获得令牌,我已完成以下操作:
一种Invalid here.token
3 , "Qt Location requires app_id and token parameters.\nPlease register at https://developer.here.com/ to get your personal application credentials."
Run Code Online (Sandbox Code Playgroud)
我错过了在 Qt 中显示 here 插件的令牌吗?
The HERE service has been updated but Qt has not updated its plugin.
The main changes are:
The app_id and token is only necessary when using the HERE SDK, in the case of Qt the apiKey must be used.
The HERE services url has had the following changes:
Use https (it was previously accessible through http but not now).
The previous host had the format X.api.here.com but now it is X.ls.hereapi.com.
That is, you have to change the request from:
http://X.api.here.com/?app_code={here.app_code}&app_id={here.app_id}&{other_parameters}
Run Code Online (Sandbox Code Playgroud)
to
https://X.ls.here.com/?apiKey={here.apiKey}&{other_parameters}
Run Code Online (Sandbox Code Playgroud)
Qt 5.14:
Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:
git clone https://code.qt.io/qt/qtlocation.git
cd qtlocation
git checkout 5.14
wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.14/update-HERE-Qt5.14.patch
git config --global user.email "you@example.com"
git am < update-HERE-Qt5.14.patch
qmake .
make
make install
Run Code Online (Sandbox Code Playgroud)
Qt 5.9:
Considering the above I have created a patch that implements the above, so to use it you must follow the following procedure:
git clone https://code.qt.io/qt/qtlocation.git
cd qtlocation
git checkout 5.9
wget https://raw.githubusercontent.com/eyllanesc/stackoverflow/master/questions/60544057/Qt5.9/update-HERE-Qt5.9.patch
git config --global user.email "you@example.com"
git am < update-HERE-Qt5.9.patch
qmake .
make
make install
Run Code Online (Sandbox Code Playgroud)
Window {
visible: true
width: 640
height: 480
Plugin {
id: mapPlugin
name: "here"
PluginParameter { name: "here.apiKey"; value: "{YOUR_API_KEY}" }
}
Map {
anchors.fill: parent
plugin: mapPlugin
center: QtPositioning.coordinate(59.91, 10.75) // Oslo
zoomLevel: 14
}
}
Run Code Online (Sandbox Code Playgroud)
Here service provides various authentication systems with different access urls. So considering the above I have tried each of those cases and I have found that Qt uses HERE SDK FOR IO or HERE SDK FOR ANDROID (in my part before my answer it is used for authentication type REST).
So in this case you must activate one of those types of authentications:
In the case of the HERE SDK FOR IOS or HERE SDK FOR ANDROID you must set any value for the bundle or package name, respectively.
So you must use APP ID for here.app_id and APP CODE for here.token:
Plugin {
id: mapPlugin
name: "here"
parameters: [
PluginParameter {
name: "here.app_id"
value: "APP_ID"
},
PluginParameter {
name: "here.token"
value: "APP_CODE"
}
]
}
Run Code Online (Sandbox Code Playgroud)