@ NonNull public static String encode ( @ NonNull final List < Point > path , int precision ) { long lastLat = 0 ; long lastLng = 0 ; final StringBuilder result = new StringBuilder ( ) ; // OSRM uses precision=6, the default Polyline spec divides by 1E5, capping at precision=5 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 ( ) ; }
Encodes a sequence of Points into an encoded path string .