Marble/Runners/Search
Editing Projects/Marble/MarbleCPlusPlus
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
Tutorial Series | Marble C++ Tutorial |
Previous | None |
What's Next | Tutorial 8 - Reverse Geocoding |
Further Reading | n/a |
Searching for cities, addresses, points of interest
Marble uses so-called runners to calculate routes, do reverse geocoding, parse files and search for placemarks (cities, addresses, points of interest, ...). This tutorial shows how to use the MarbleRunnerManager class to search for an arbitrary string (Karlsruhe in the example below, see Userbase for more information on search terms).
#include <QtGui/QApplication>
#include <QtCore/QDebug>
#include <marble/MarbleWidget.h>
#include <marble/MarbleModel.h>
#include <marble/MarbleRunnerManager.h>
#include <marble/GeoDataPlacemark.h>
using namespace Marble;
int main(int argc, char** argv)
{
QApplication app(argc,argv);
MarbleWidget *mapWidget = new MarbleWidget;
MarbleModel *model = mapWidget->model();
MarbleRunnerManager* manager = new MarbleRunnerManager( model->pluginManager() );
manager->setModel( model );
QVector<GeoDataPlacemark*> searchResult = manager->searchPlacemarks( "Karlsruhe" );
foreach( GeoDataPlacemark* placemark, searchResult ) {
qDebug() << "Found " << placemark->name() << "at" << placemark->coordinate().toString();
}
}
Copy and paste the code above into a text editor. Then save it as my_marble.cpp and compile it by entering the following command on the command line:
g++ -I /usr/include/qt4/ -o my_marble my_marble.cpp -lmarblewidget -lQtGui -lQtCore
If things go fine, execute ./my_marble and the output looks similar to this:
Found "Karlsruhe, Germany" at " 8° 33' 48.7"E, 49° 05' 38.4"N"
Found "Karlsruhe, McLean" at "100° 36' 58.4"W, 48° 05' 27.7"N"
Found "Karlsruhe, Karlsruhe, Stadt" at " 8° 24' 16.0"E, 49° 00' 50.6"N"
Found "Karlsruhe, Remscheid" at " 7° 17' 35.3"E, 51° 09' 09.4"N"
Found "Karlsruhe, Austria" at " 15° 19' 53.6"E, 47° 21' 33.4"N"
Found "Karlsruhe, McLean" at "100° 37' 13.5"W, 48° 05' 24.0"N"
Found "Karlsruhe, Sohland a.d. Spree" at " 14° 27' 36.5"E, 51° 02' 28.5"N"
Found "Parkstraße, Bad Elster" at " 12° 14' 08.0"E, 50° 16' 57.9"N"
Found "Karlsruhe (Bruchsal)" at " 8° 33' 48.7"E, 49° 05' 38.4"N"
Found "Karlsruhe (Innenstadt-West)" at " 8° 24' 16.0"E, 49° 00' 50.6"N"
- You need Qt and Marble development packages (or comparable git installations), version 1.3 (Marble library 0.13), shipped e.g. with KDE 4.8
- 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