以下是使用 C++ 代码在 QWidget 上设置 Piamap 的示例:
#include <QApplication>
#include <QWidget>
#include <QVBoxLayout>
#include <QtPiamap/QPiamap.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
// Create a QWidget for displaying the map
QWidget window;
QVBoxLayout *layout = new QVBoxLayout(&window);
// Create a QPiamap object and add it to the layout
QPiamap *map = new QPiamap(&window);
layout->addWidget(map);
// Set the API key for the map
map->setApiKey("YOUR_API_KEY");
// Set the center of the map and the zoom level
map->setCenter(QGeoCoordinate(49.2827, -123.1207));
map->setZoomLevel(14);
// Show the widget and run the event loop
window.show();
return app.exec();
}
注意,您需要将 YOUR_API_KEY
替换为您自己的 Piamap API 密钥。如果您没有密钥,请先注册账户,并按照文档中的说明获取密钥。