PolylineUtils { @NonNull public static String encode(@NonNull final List<Point> path, int precision) { long lastLat = 0; long lastLng = 0; final StringBuilder result = new StringBuilder(); double factor = Math.pow(10, precision); for (final Point point : path) { long lat = Math.round(point.latitude() * factor); long lng = Math.round(point.longitude() * factor); long varLat = lat - lastLat; long varLng = lng - lastLng; encode(varLat, result); encode(varLng, result); lastLat = lat; lastLng = lng; } return result.toString(); } private  PolylineUtils(); @NonNull static List<Point> decode(@NonNull final String encodedPath, int precision); @NonNull static String encode(@NonNull final List<Point> path, int precision); @NonNull static List<Point> simplify(@NonNull List<Point> points); @NonNull static List<Point> simplify(@NonNull List<Point> points, double tolerance); @NonNull static List<Point> simplify(@NonNull List<Point> points, boolean highestQuality); @NonNull static List<Point> simplify(@NonNull List<Point> points, double tolerance,
                                     boolean highestQuality);  }
@Test public void testFromPolyline6() { List<Point> originalPath = Arrays.asList( Point.fromLngLat(2.2862036, 48.8267868), Point.fromLngLat(2.4, 48.9) ); String encoded = encode(originalPath, PRECISION_6); List<Point> path = LineString.fromPolyline(encoded, PRECISION_6).coordinates(); assertEquals(originalPath.size(), path.size()); for (int i = 0; i < originalPath.size(); i++) { assertEquals(originalPath.get(i).latitude(), path.get(i).latitude(), DELTA); assertEquals(originalPath.get(i).longitude(), path.get(i).longitude(), DELTA); } }
@Test public void encode_neverReturnsNull() throws Exception { String encodedString = encode(new ArrayList<Point>(), PRECISION_6); assertNotNull(encodedString); }