diff --git a/OsmAnd-java/src/net/osmand/util/GeoPolylineParserUtil.java b/OsmAnd-java/src/net/osmand/util/GeoPolylineParserUtil.java index eee0faeaa8..491ec35742 100644 --- a/OsmAnd-java/src/net/osmand/util/GeoPolylineParserUtil.java +++ b/OsmAnd-java/src/net/osmand/util/GeoPolylineParserUtil.java @@ -5,17 +5,19 @@ import java.util.ArrayList; import java.util.List; public class GeoPolylineParserUtil { + + public static final double PRECISION_6 = 1E6; + public static final double PRECISION_5 = 1E5; /** * Parses Google esque polyline * * @param encoded The polyline as a String * @return {@link List} */ - public static List parse(final String encoded) { + public static List parse(final String encoded, double precision) { List track = new ArrayList(); int index = 0; int lat = 0, lng = 0; - double precision = 1E5; while (index < encoded.length()) { int b, shift = 0, result = 0; diff --git a/OsmAnd-java/test/java/net/osmand/util/GeoPolylineParserUtilTest.java b/OsmAnd-java/test/java/net/osmand/util/GeoPolylineParserUtilTest.java index 5b5895a280..7112f69962 100644 --- a/OsmAnd-java/test/java/net/osmand/util/GeoPolylineParserUtilTest.java +++ b/OsmAnd-java/test/java/net/osmand/util/GeoPolylineParserUtilTest.java @@ -3,6 +3,7 @@ package net.osmand.util; import net.osmand.data.LatLon; import java.util.Arrays; + import org.junit.Assert; import org.junit.Test; @@ -13,6 +14,8 @@ import org.junit.Test; public class GeoPolylineParserUtilTest { @Test public void testDecode() { + + Assert.assertEquals(Arrays.asList( new LatLon(52.503032, 13.420526), new LatLon(52.503240, 13.420671), @@ -83,6 +86,7 @@ public class GeoPolylineParserUtilTest { GeoPolylineParserUtil.parse("" + "o~occB{}brX_LaHyY{QaW}OoN{IoHuEcIcFeM}HoKyGuBsARmG`@yJVwKXaZIqT_@sUi@kNgCk`@wAePsCwTwDuTsG}Y" + "wIsZgFuMmB_F_HmQ}NoVgFyGoCsDmK}KgLaJuHeEgEyCiHcFgE}BeGo@mIKoQW{JwBwHeFmFmDePcNuJqIqk@sf@{EiE" + - "mU}RoGkDwPoGeD|K{U`z@_Vpy@}\\pbAsJ}B}NqCyEy@yI}A_WeFeSyEqToJu^_Nmv@ge@{MyI}TcJkTeGcg@oMgCm@")); + "mU}RoGkDwPoGeD|K{U`z@_Vpy@}\\pbAsJ}B}NqCyEy@yI}A_WeFeSyEqToJu^_Nmv@ge@{MyI}TcJkTeGcg@oMgCm@", + GeoPolylineParserUtil.PRECISION_6)); } } diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index 8a05d8ca64..6ae0a90930 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -1205,7 +1205,8 @@ public class RouteProvider { rs.close(); } catch(IOException e){ } - List route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry")); + List route = GeoPolylineParserUtil.parse(obj.getJSONArray("routes").getJSONObject(0).getString("geometry"), + GeoPolylineParserUtil.PRECISION_5); if (route.isEmpty()) { return new RouteCalculationResult("Route is empty"); }