Marble/Runners/ReverseGeocoding: Difference between revisions

From KDE TechBase
(Created page with "{{Template:I18n/Language Navigation Bar|Editing Projects/Marble/MarbleCPlusPlus}} {{TutorialBrowser| series=Marble C++ Tutorial| name=Basic Routing| pre=[[Projects/Marble/Laye...")
 
No edit summary
Line 6: Line 6:
name=Basic Routing|
name=Basic Routing|


pre=[[Projects/Marble/LayerInterface|Tutorial 5 - Drawing in Custom Layers]]|
pre=[[Projects/Marble/Runners/Search|Tutorial 7 - Searching]]|


next=[[Projects/Marble/Runners/Search|Tutorial 7 - Searching]]|  
next=[[Projects/Marble/Runners/Parse|Tutorial 9 - Opening .kml, .gpx, ... files]]|
}}
}}



Revision as of 13:28, 7 January 2012


Editing Projects/Marble/MarbleCPlusPlus

Basic Routing
Tutorial Series   Marble C++ Tutorial
Previous   Tutorial 7 - Searching
What's Next   Tutorial 9 - Opening .kml, .gpx, ... files
Further Reading   n/a

Reverse geocoding

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 get a textual description of a given coordinate.

#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 );

    GeoDataCoordinates position( -0.15845,  51.52380, 0.0, GeoDataCoordinates::Degree );
    qDebug() << position.toString() << "is" << manager->searchReverseGeocoding( position );
}

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:

"  0° 09' 30.4"W,  51° 31' 25.7"N" is "Sherlock Holmes Museum, "221b", Baker Street, Marylebone, City of Westminster, Greater London, England, NW1 6AX, United Kingdom"
Tip
Here's a little checklist to tackle some problems that might arise when compiling the code above:
  • You need Qt and Marble development packages (or comparable git installations), version 1.3 (Marble library 0.13), shipped post 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
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.