Difference between revisions of "Projects/Marble/Runners/Search"

Jump to: navigation, search
(Searching for cities, addresses, points of interest)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Template:I18n/Language Navigation Bar|Editing Projects/Marble/MarbleCPlusPlus}}
+
 
 
{{TutorialBrowser|
 
{{TutorialBrowser|
  
Line 6: Line 6:
 
name=Search|
 
name=Search|
  
pre=[[Projects/Marble/Routing/BasicRouting|Tutorial 6 - Basic Routing]]|
+
pre=[[Projects/Marble/Routing/BasicRouting|Tutorial 9 - Basic Routing]]|
  
next=[[Projects/Marble/Runners/ReverseGeocoding|Tutorial 8 - Reverse Geocoding]]|  
+
next=[[Projects/Marble/Runners/ReverseGeocoding|Tutorial 11 - Reverse Geocoding]]|  
 
}}
 
}}
  
Line 28: Line 28:
 
{
 
{
 
     QApplication app(argc,argv);
 
     QApplication app(argc,argv);
     MarbleWidget *mapWidget = new MarbleWidget;
+
     MarbleModel *model = new MarbleModel;
    MarbleModel *model = mapWidget->model();
+
 
      
 
      
 
     MarbleRunnerManager* manager = new MarbleRunnerManager( model->pluginManager() );
 
     MarbleRunnerManager* manager = new MarbleRunnerManager( model->pluginManager() );

Latest revision as of 17:55, 13 January 2013

Search
Tutorial Series   Marble C++ Tutorial
Previous   Tutorial 9 - Basic Routing
What's Next   Tutorial 11 - Reverse Geocoding
Further Reading   n/a

[edit] 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);
    MarbleModel *model = new MarbleModel;
 
    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"
Ktip.png
 
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
noframe
 
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.

This page was last modified on 13 January 2013, at 17:55. This page has been accessed 3,409 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal