Adding a simple example on how to call the lib
This commit is contained in:
parent
c940c2722e
commit
a0e9f59e04
@ -67,6 +67,9 @@ target_link_libraries( osrm-extract ${Boost_LIBRARIES} )
|
|||||||
target_link_libraries( osrm-prepare ${Boost_LIBRARIES} )
|
target_link_libraries( osrm-prepare ${Boost_LIBRARIES} )
|
||||||
target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM)
|
target_link_libraries( osrm-routed ${Boost_LIBRARIES} OSRM)
|
||||||
|
|
||||||
|
add_executable ( osrm-cli simpleclient.cpp)
|
||||||
|
target_link_libraries( osrm-cli ${Boost_LIBRARIES} OSRM)
|
||||||
|
|
||||||
find_package ( BZip2 REQUIRED )
|
find_package ( BZip2 REQUIRED )
|
||||||
include_directories(${BZIP_INCLUDE_DIRS})
|
include_directories(${BZIP_INCLUDE_DIRS})
|
||||||
target_link_libraries (osrm-extract ${BZIP2_LIBRARIES})
|
target_link_libraries (osrm-extract ${BZIP2_LIBRARIES})
|
||||||
|
@ -33,7 +33,8 @@ struct _Coordinate {
|
|||||||
int lat;
|
int lat;
|
||||||
int lon;
|
int lon;
|
||||||
_Coordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
_Coordinate () : lat(INT_MIN), lon(INT_MIN) {}
|
||||||
_Coordinate (int t, int n) : lat(t) , lon(n) {}
|
explicit _Coordinate (int t, int n) : lat(t) , lon(n) {}
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
lat = INT_MIN;
|
lat = INT_MIN;
|
||||||
lon = INT_MIN;
|
lon = INT_MIN;
|
||||||
|
@ -30,13 +30,9 @@ class TimestampPlugin : public BasePlugin {
|
|||||||
public:
|
public:
|
||||||
TimestampPlugin(QueryObjectsStorage * o) : objects(o) {
|
TimestampPlugin(QueryObjectsStorage * o) : objects(o) {
|
||||||
}
|
}
|
||||||
~TimestampPlugin() {
|
|
||||||
std::cout << "shutdown time stamp" << std::endl;
|
|
||||||
}
|
|
||||||
std::string GetDescriptor() const { return std::string("timestamp"); }
|
std::string GetDescriptor() const { return std::string("timestamp"); }
|
||||||
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
std::string GetVersionString() const { return std::string("0.3 (DL)"); }
|
||||||
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
void HandleRequest(const RouteParameters & routeParameters, http::Reply& reply) {
|
||||||
std::cout << "handling request" << std::endl;
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
|
|
||||||
//json
|
//json
|
||||||
|
89
simpleclient.cpp
Normal file
89
simpleclient.cpp
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
open source routing machine
|
||||||
|
Copyright (C) Dennis Luxen, 2010
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU AFFERO General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
or see http://www.gnu.org/licenses/agpl.txt.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Library/OSRM.h"
|
||||||
|
#include "Plugins/RouteParameters.h"
|
||||||
|
#include "Server/BasicDatastructures.h"
|
||||||
|
|
||||||
|
#include <boost/property_tree/ptree.hpp>
|
||||||
|
#include <boost/property_tree/json_parser.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stack>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
//Dude, real recursions on the OS stack? You must be brave...
|
||||||
|
void print_tree(boost::property_tree::ptree const& pt, const unsigned recursion_depth)
|
||||||
|
{
|
||||||
|
boost::property_tree::ptree::const_iterator end = pt.end();
|
||||||
|
for (boost::property_tree::ptree::const_iterator it = pt.begin(); it != end; ++it) {
|
||||||
|
for(unsigned i = 0; i < recursion_depth; ++i) {
|
||||||
|
std::cout << " " << std::flush;
|
||||||
|
}
|
||||||
|
std::cout << it->first << ": " << it->second.get_value<std::string>() << std::endl;
|
||||||
|
print_tree(it->second, recursion_depth+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main (int argc, char * argv[]) {
|
||||||
|
std::cout << "\n starting up engines, compile at "
|
||||||
|
<< __DATE__ << ", " __TIME__ << std::endl;
|
||||||
|
BaseConfiguration serverConfig((argc > 1 ? argv[1] : "server.ini"));
|
||||||
|
OSRM routing_machine((argc > 1 ? argv[1] : "server.ini"));
|
||||||
|
|
||||||
|
RouteParameters route_parameters;
|
||||||
|
route_parameters.zoomLevel = 18; //no generalization
|
||||||
|
route_parameters.printInstructions = true; //turn by turn instructions
|
||||||
|
route_parameters.alternateRoute = true; //get an alternate route, too
|
||||||
|
route_parameters.geometry = true; //retrieve geometry of route
|
||||||
|
route_parameters.compression = true; //polyline encoding
|
||||||
|
route_parameters.checkSum = UINT_MAX; //see wiki
|
||||||
|
route_parameters.service = "viaroute"; //that's routing
|
||||||
|
route_parameters.outputFormat = "json";
|
||||||
|
route_parameters.jsonpParameter = ""; //set for jsonp wrapping
|
||||||
|
route_parameters.language = ""; //unused atm
|
||||||
|
//route_parameters.hints.push_back(); // see wiki, saves I/O if done properly
|
||||||
|
|
||||||
|
_Coordinate start_coordinate(52.519930*100000,13.438640*100000);
|
||||||
|
_Coordinate target_coordinate(52.513191*100000,13.415852*100000);
|
||||||
|
route_parameters.coordinates.push_back(start_coordinate);
|
||||||
|
route_parameters.coordinates.push_back(target_coordinate);
|
||||||
|
|
||||||
|
http::Reply osrm_reply;
|
||||||
|
|
||||||
|
routing_machine.RunQuery(route_parameters, osrm_reply);
|
||||||
|
|
||||||
|
std::cout << osrm_reply.content << std::endl;
|
||||||
|
|
||||||
|
//attention: super-inefficient hack below:
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << osrm_reply.content;
|
||||||
|
|
||||||
|
boost::property_tree::ptree pt;
|
||||||
|
boost::property_tree::read_json(ss, pt);
|
||||||
|
|
||||||
|
print_tree(pt, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user