在QT 5中重新设置QT/QML映射
Recenter QT/QML Map in Qt 5
各位程序员好,
我想做的是用下面的QML重新中心我的地图。坐标是一对数字而不是像地图视图那样是地址
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();
}
就像前面提到的,在早期版本中这是有效的:
function centermyposition(){ //sets my position, but only once (do not update automatically)
var coord = Qt.createQmlObject('import QtMobility.location 1.1; Coordinate{latitude:' + positionSource.position.coordinate.latitude + ';longitude:' + positionSource.position.coordinate.longitude + ';}', positionSource, "coord");
map.center = coord;
myMapRoot.updateViewport()
}
我找到了一个适合我的解决方案:
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
}
}
}
相关文章:
- QT设置了所有对象以外的所有对象样式
- QT设置iOS屏幕方向
- QT设置leandit的文本
- 如何在Mac OS X上使用Qt设置libusb?(尝试跨平台方法)
- Qt- 设置来自表视图的输入的验证器
- 如何通过QT 5.6设置QML应用程序窗口透明
- QT设置了QplaintExtedIt的滚动区域,以匹配Anothers的滚动区域
- 用GCC 4.6.2 C QT设置堆栈大小,Mingw,Vista
- C++Qt-设置QTableWidget项的值
- 使用Qt C ++设置手动位置并创建文件
- Qt 设置了 QLineEdit 的背景颜色
- Qt 设置选项卡栏
- Qt设置QWidget的默认宽度
- Qt-设置.o文件的输出路径
- 如何使用QT设置PATH变量
- Qt -设置不可编辑的QComboBox的显示文本
- 如何在OSX中使用QT设置OpenCV
- Qt设置背景颜色的QPushButton
- Qt 设置几何图形为负值不起作用
- Qt -设置伙伴