Skip to content

Commit

Permalink
Library example now shows, how to use different output formats.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Chaplygin committed Aug 26, 2019
1 parent a196e67 commit ff46e98
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ int main(int argc, const char *argv[])
params.coordinates.push_back({util::FloatLongitude{7.419505}, util::FloatLatitude{43.736825}});

// Response is in JSON format
json::Object result;
engine::api::ResultT result = json::Object();

// Execute routing request, this does the heavy lifting
const auto status = osrm.Route(params, result);

auto& json_result=result.get<json::Object>();
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
auto &route = routes.values.at(0).get<json::Object>();
Expand All @@ -79,8 +80,8 @@ int main(int argc, const char *argv[])
}
else if (status == Status::Error)
{
const auto code = result.values["code"].get<json::String>().value;
const auto message = result.values["message"].get<json::String>().value;
const auto code = json_result.values["code"].get<json::String>().value;
const auto message = json_result.values["message"].get<json::String>().value;

std::cout << "Code: " << code << "\n";
std::cout << "Message: " << code << "\n";
Expand Down

0 comments on commit ff46e98

Please sign in to comment.