Library example now shows, how to use different output formats.
This commit is contained in:
parent
a196e67e1a
commit
ff46e98d21
@ -52,14 +52,15 @@ int main(int argc, const char *argv[])
|
|||||||
params.coordinates.push_back({util::FloatLongitude{7.419505}, util::FloatLatitude{43.736825}});
|
params.coordinates.push_back({util::FloatLongitude{7.419505}, util::FloatLatitude{43.736825}});
|
||||||
|
|
||||||
// Response is in JSON format
|
// Response is in JSON format
|
||||||
json::Object result;
|
engine::api::ResultT result = json::Object();
|
||||||
|
|
||||||
// Execute routing request, this does the heavy lifting
|
// Execute routing request, this does the heavy lifting
|
||||||
const auto status = osrm.Route(params, result);
|
const auto status = osrm.Route(params, result);
|
||||||
|
|
||||||
|
auto& json_result=result.get<json::Object>();
|
||||||
if (status == Status::Ok)
|
if (status == Status::Ok)
|
||||||
{
|
{
|
||||||
auto &routes = result.values["routes"].get<json::Array>();
|
auto &routes = json_result.values["routes"].get<json::Array>();
|
||||||
|
|
||||||
// Let's just use the first route
|
// Let's just use the first route
|
||||||
auto &route = routes.values.at(0).get<json::Object>();
|
auto &route = routes.values.at(0).get<json::Object>();
|
||||||
@ -79,8 +80,8 @@ int main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
else if (status == Status::Error)
|
else if (status == Status::Error)
|
||||||
{
|
{
|
||||||
const auto code = result.values["code"].get<json::String>().value;
|
const auto code = json_result.values["code"].get<json::String>().value;
|
||||||
const auto message = result.values["message"].get<json::String>().value;
|
const auto message = json_result.values["message"].get<json::String>().value;
|
||||||
|
|
||||||
std::cout << "Code: " << code << "\n";
|
std::cout << "Code: " << code << "\n";
|
||||||
std::cout << "Message: " << code << "\n";
|
std::cout << "Message: " << code << "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user