C++ 在QT 5中重新居中QT/QML映射
亲爱的程序员您好 我要做的是使用以下QML重新居中我的地图。 我确实把坐标作为一对数字,而不像地图视图示例中的地址C++ 在QT 5中重新居中QT/QML映射,c++,qt,C++,Qt,亲爱的程序员您好 我要做的是使用以下QML重新居中我的地图。 我确实把坐标作为一对数字,而不像地图视图示例中的地址 ApplicationWindow { visible: true width: 720 height: 1280 title: qsTr("") id: root Map { id: map anchors.centerIn: parent; anchors.fill: parent
ApplicationWindow {
visible: true
width: 720
height: 1280
title: qsTr("")
id: root
Map {
id: map
anchors.centerIn: parent;
anchors.fill: parent
zoomLevel: 11
objectName: "mainMap"
center {
id: mapCenter
latitude : 50.89
longitude: 11.23
}
plugin: Plugin {
name: "here"
PluginParameter { name: "here.app_id"; value: "R9qav4Kw6gO5XKSxNiOO" }
PluginParameter { name: "here.token"; value: "58UCNRCr1dZxhLL2Bmmz3Q" }
PluginParameter { name: "here.proxy"; value: "system" }
}
function setPosition(pos) {
map.toCoordinate(pos);
map.update();
}
}
C++的一方相对来说比较简单。 这是我迄今为止最好的一次拍摄,直接改变纬度和逻辑度似乎从未奏效。早期版本的工作原理是创建一个新对象作为坐标,然后将其提供给地图
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QObject>
#include <QTime>
#include <QBasicTimer>
#include <QDebug>
#include <QEasingCurve>
#include <QGeoCoordinate>
#include <QtPositioning/private/qgeoprojection_p.h>
#include <QGeoServiceProvider>
#include <QDebug>
#include <QNetworkRequest>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QUrl data("https://lstsim.de/js/dispatch/1.js");
QNetworkRequest request(data);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *rootObject = engine.rootObjects().first();
QObject* mainMapCenter = rootObject->findChild<QObject*>("mainMap");
if(mainMapCenter != NULL){
QVariant returnedValue;
QPoint point(12,12);
QMetaObject::invokeMethod(mainMapCenter, "setPosition",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, point));
qDebug() << "found map";
}
return app.exec();
}
我找到了一个适合我的解决方案:
ApplicationWindow {
Location {
id: mapCentre
coordinate {
latitude: -27.5
longitude: 153.1
}
}
Map {
id: map
anchors.centerIn: parent;
anchors.fill: parent
zoomLevel: 11
objectName: "mainMap"
function recenter(lat,lng) {
mapCentre.coordinate.latitude = lat
mapCentre.coordinate.longitude = lng
}
}
}
ApplicationWindow {
Location {
id: mapCentre
coordinate {
latitude: -27.5
longitude: 153.1
}
}
Map {
id: map
anchors.centerIn: parent;
anchors.fill: parent
zoomLevel: 11
objectName: "mainMap"
function recenter(lat,lng) {
mapCentre.coordinate.latitude = lat
mapCentre.coordinate.longitude = lng
}
}
}