Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix routing coordinate format #1189

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/routing/ors_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ std::string OrsWrapper::build_query(const std::vector<Location>& locations,
}
body += "\":[";
for (auto const& location : locations) {
body += std::format("[{},{}],", location.lon(), location.lat());
body += std::format("[{:.6f},{:.6f}],", location.lon(), location.lat());
}
body.pop_back(); // Remove trailing ','.
body += "]";
Expand Down
7 changes: 4 additions & 3 deletions src/routing/osrm_routed_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ OsrmRoutedWrapper::build_query(const std::vector<Location>& locations,

// Adding locations and radiuses values.
for (auto const& location : locations) {
query += std::format("{},{};", location.lon(), location.lat());
query += std::format("{:.6f},{:.6f};", location.lon(), location.lat());
radiuses += DEFAULT_OSRM_SNAPPING_RADIUS + ";";
}
// Remove trailing ';'.
Expand Down Expand Up @@ -74,8 +74,9 @@ void OsrmRoutedWrapper::check_response(const rapidjson::Document& json_result,
const auto error_loc =
std::stoul(message.substr(snapping_error_base.size(),
message.size() - snapping_error_base.size()));
const auto coordinates =
std::format("[{},{}]", locs[error_loc].lon(), locs[error_loc].lat());
const auto coordinates = std::format("[{:.6f},{:.6f}]",
locs[error_loc].lon(),
locs[error_loc].lat());
throw RoutingException("Could not find route near location " +
coordinates);
}
Expand Down
7 changes: 4 additions & 3 deletions src/routing/valhalla_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ std::string ValhallaWrapper::get_matrix_query(
// List locations.
std::string all_locations;
for (auto const& location : locations) {
all_locations +=
std::format(R"({{"lon":{},"lat":{}}},)", location.lon(), location.lat());
all_locations += std::format(R"({{"lon":{:.6f},"lat":{:.6f}}},)",
location.lon(),
location.lat());
}
all_locations.pop_back(); // Remove trailing ','.

Expand All @@ -61,7 +62,7 @@ ValhallaWrapper::get_route_query(const std::vector<Location>& locations) const {
"GET /" + _server.path + _route_service + "?json={\"locations\":[";

for (auto const& location : locations) {
query += std::format(R"({{"lon":{},"lat":{},"type":"break"}},)",
query += std::format(R"({{"lon":{:.6f},"lat":{:.6f},"type":"break"}},)",
location.lon(),
location.lat());
}
Expand Down
2 changes: 1 addition & 1 deletion src/routing/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class Wrapper {
if (max_unfound_routes_for_a_loc > 0) {
std::string error_msg = "Unfound route(s) ";
error_msg += error_direction;
error_msg += std::format("location [{},{}]",
error_msg += std::format("location [{:.6f},{:.6f}]",
locs[error_loc].lon(),
locs[error_loc].lat());

Expand Down