From 0cfe5d468de47d1aaf4525d6ca593c86687352f1 Mon Sep 17 00:00:00 2001 From: osMatt Date: Mon, 19 Sep 2016 20:07:49 -0600 Subject: [PATCH] Fix #3055 I don't have a development environment set up to actually test these changes locally, so please review thoroughly. Thanks! --- .../net/osmand/plus/routing/RouteProvider.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 7986f75953..e62830d4e8 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -60,6 +60,7 @@ import net.osmand.util.MapUtils; import net.osmand.util.GeoPolylineParserUtil; import org.json.JSONObject; +import org.json.JSONArray; import org.json.JSONException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -1159,13 +1160,13 @@ public class RouteProvider { } private void appendOSRMLoc(StringBuilder uri, LatLon il) { - uri.append("&loc=").append(String.valueOf(il.getLatitude())); - uri.append(",").append(String.valueOf(il.getLongitude())); + uri.append(";").append(String.valueOf(il.getLongitude())); + uri.append(",").append(String.valueOf(il.getLatitude())); } protected RouteCalculationResult findOSRMRoute(RouteCalculationParams params) throws MalformedURLException, IOException, JSONException { - // https://router.project-osrm.org/viaroute?loc=52.28,4.83&loc=52.35,4.95&alt=false&output=gpx + // http://router.project-osrm.org/route/v1/driving/4.83,52.28;4.95,52.28 List res = new ArrayList(); StringBuilder uri = new StringBuilder(); // possibly hide that API key because it is privacy of osmand @@ -1177,15 +1178,17 @@ public class RouteProvider { // } else { scheme = "http"; // } - uri.append(scheme + "://router.project-osrm.org/viaroute?alt=false"); //$NON-NLS-1$ - uri.append("&loc=").append(String.valueOf(params.start.getLatitude())); - uri.append(",").append(String.valueOf(params.start.getLongitude())); + uri.append(scheme + "://router.project-osrm.org/route/v1/driving/"); //$NON-NLS-1$ + uri.append(String.valueOf(params.start.getLongitude())); + uri.append(",").append(String.valueOf(params.start.getLatitude())); if(params.intermediates != null && params.intermediates.size() > 0) { for(LatLon il : params.intermediates) { appendOSRMLoc(uri, il); } } appendOSRMLoc(uri, params.end); +// to get more waypoints, add overview=full option +// uri.append("?overview=full") log.info("URL route " + uri); @@ -1202,7 +1205,7 @@ public class RouteProvider { rs.close(); } catch(IOException e){ } - List route = GeoPolylineParserUtil.parse(obj.get("route_geometry").toString()); + List route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry")); if (route.isEmpty()) { return new RouteCalculationResult("Route is empty"); }