code: public static String encode(final List<LatLng> path) {
      long lastLat = 0;
      long lastLng = 0;
  
      final StringBuilder result = new StringBuilder();
  
      for (final LatLng point : path) {
        long lat = Math.round(point.lat * 1e5);
        long lng = Math.round(point.lng * 1e5);
  
        long dLat = lat - lastLat;
        long dLng = lng - lastLng;
  
        encode(dLat, result);
        encode(dLng, result);
  
        lastLat = lat;
        lastLng = lng;
      }
      return result.toString();
    }
docs: Encodes a sequence of LatLngs into an encoded path string.