The Marble API allows a very easy integration of a map widget in your application. Let's prove that with a tiny "Hello world"-like example:

+

The API of the Marble library allows for a very easy integration of a '''map widget''' into your application.

−

<code cppqt>

+

Let's prove that with a tiny '''Hello world'''-like example: Qt beginners might want to have a look at the [http://doc.trolltech.com/widgets-tutorial.html Qt Widgets Tutorial] to learn more about the details of the code. But this is probably not necessary. For a start we just create a [http://doc.trolltech.com/qapplication.html QApplication] object and a [http://api.kde.org/4.x-api/kdeedu-apidocs/marble/html/classMarble_1_1MarbleWidget.html MarbleWidget] object which serves as a window.

+

By default the MarbleWidget uses the ''Atlas'' map theme. However for our first example we choose to display streets. So we set the maptheme id to

+

[http://www.openstreetmap.org OpenStreetMap]. Then we call [http://doc.trolltech.com/qwidget.html#show QWidget::show()] to show the map widget and we call [http://doc.trolltech.com/qapplication.html#exec QApplication::exec()] to start the application's event loop. That's all!

+

<source lang="cpp-qt">

#include <QtGui/QApplication>

#include <QtGui/QApplication>

#include <marble/MarbleWidget.h>

#include <marble/MarbleWidget.h>

Line 32:

Line 35:

mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");

mapWidget->setMapThemeId("earth/openstreetmap/openstreetmap.dgml");

−

// Set a server for downloading map data, if needed

−

mapWidget->setDownloadUrl("http://download.kde.org/apps/marble/");

mapWidget->show();

mapWidget->show();

return app.exec();

return app.exec();

}

}

+

</source>

−

</code>

+

Copy and paste the code above into a text editor. Then save it as <tt>my_marble.cpp</tt> and compile it by entering the following command on the command line:

* If you're running Marble from SVN, add the Marble:: prefix to the MarbleWidget above. The Marble namespace was added some time ago.

+

* If ''Qt headers'' are not installed in '''/usr/include/qt4''' on your system, change the path in the g++ call above accordingly.

−

* If Qt headers are not installed in /usr/include/qt4 on your system, change the path in the g++ call above accordingly.

+

* Likewise, '''add -I /path/to/marble/headers''' if they're not to be found in /usr/include

−

* Likewise, add -I /path/to/marble/headers if they're not to be found in /usr/include

+

}}

+

{{note|

+

If you provide maps in your application please check the '''Terms of Use''' of the map material. The map material that is shipped with Marble is licensed ''in the spirit of Free Software''. This usually means at least that the authors should be credited and that the license is mentioned.

+

E.g. for ''OpenStreetMap'' the license is [http://creativecommons.org/license/by-sa/2.0 CC-BY-SA]. Other map data shipped with Marble is either public domain or licensed in the spirit of the BSD license.

Revision as of 16:43, 15 July 2012

Hello Marble!

The API of the Marble library allows for a very easy integration of a map widget into your application.

Let's prove that with a tiny Hello world-like example: Qt beginners might want to have a look at the Qt Widgets Tutorial to learn more about the details of the code. But this is probably not necessary. For a start we just create a QApplication object and a MarbleWidget object which serves as a window.
By default the MarbleWidget uses the Atlas map theme. However for our first example we choose to display streets. So we set the maptheme id to
OpenStreetMap. Then we call QWidget::show() to show the map widget and we call QApplication::exec() to start the application's event loop. That's all!

If Qt headers are not installed in /usr/include/qt4 on your system, change the path in the g++ call above accordingly.

Likewise, add -I /path/to/marble/headers if they're not to be found in /usr/include

Note

If you provide maps in your application please check the Terms of Use of the map material. The map material that is shipped with Marble is licensed in the spirit of Free Software. This usually means at least that the authors should be credited and that the license is mentioned.
E.g. for OpenStreetMap the license is CC-BY-SA. Other map data shipped with Marble is either public domain or licensed in the spirit of the BSD license.