From 06875ba5985ab9a628a7cfef1cfbb9ebc26662b5 Mon Sep 17 00:00:00 2001 From: ExMix Date: Tue, 16 Sep 2014 12:00:42 +0300 Subject: [PATCH] [core] support of new OSRM format response --- routing/osrm_router.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/routing/osrm_router.cpp b/routing/osrm_router.cpp index 5ea086ca81..0f8a0f098a 100644 --- a/routing/osrm_router.cpp +++ b/routing/osrm_router.cpp @@ -62,11 +62,27 @@ void OsrmRouter::OnRouteReceived(downloader::HttpRequest & request, ReadyCallbac json_t const * jcoords = json_array_get(jgeometry, i); if (jcoords) { - string const coords = json_string_value(jcoords); - string const strLat(coords, 0, coords.find(',')); - string const strLon(coords, coords.find(',') + 1); double lat, lon; - if (strings::to_double(strLat, lat) && strings::to_double(strLon, lon)) + bool validCoord = false; + if (json_is_array(jcoords)) + { + if (json_array_size(jcoords) >= 2) + { + lat = json_real_value(json_array_get(jcoords, 0)); + lon = json_real_value(json_array_get(jcoords, 1)); + validCoord = true; + } + } + else if (json_is_string(jcoords)) + { + string const coords = json_string_value(jcoords); + string const strLat(coords, 0, coords.find(',')); + string const strLon(coords, coords.find(',') + 1); + if (strings::to_double(strLat, lat) && strings::to_double(strLon, lon)) + validCoord = true; + } + + if (validCoord) route.push_back(MercatorBounds::FromLatLon(lat, lon)); } }