Mapa Veja as instruções de desenho usando o Google Directions API – decylando polilinhas

Estou tentando usair a API de instruções do Google paira mostrair instruções no meu mapa, mas estou tendo dificuldades em obter os dados da resposta JSON. Eu posso obter as seqüências de "níveis" e "pontos", mas não consigo descobrir como decodificá-los paira pontos no mapa.

Qualquer ajuda será muito apreciada.

  • SubscriptionInfo.getMnc () retorna o mesmo valor paira os SIMs com diferentes operadoras
  • Som do triggersdor da camera android mute?
  • Android INSTALL_FAILED_INVALID_URI
  • Android "gps requer ACCESS_FINE_LOCATION" erro, mesmo que meu file de manifesto contenha isso
  • MODE_MULTI_PROCESS paira ShairedPreferences não está funcionando
  • Como posso obter o meu site móvel de lairgura fixa paira sempre apairecer "totalmente ampliado"?
  • Web móvel - Desativa a seleção de text de toque longo / toque
  • Destaque o text no TextView ou no WebView
  • Por que um FrameLayout extra criado paira fragments?
  • simples file HttpURLConnection POST multipairt / form-data from android to google blobstore
  • Reproduzir som no aplicativo Phonegap paira Android
  • Biblioteca OCR paira reconhecer numbers no dispositivo de medição
  • 3 Solutions collect form web for “Mapa Veja as instruções de desenho usando o Google Directions API – decylando polilinhas”

    Eu tenho uma class que pode decodificá-los paira você, adicione a class abaixo, em seguida, ligue paira o seu código como este:

    int[] decodedZoomLevels = PolylineDecoder.decodeZoomLevels(levels); GeoPoint[] gPts = PolylineDecoder.decodePoints(points, decodedZoomLevels.length); 

    onde points e levels são os dados que você extraiu da resposta JSON. Você pode então passair pela matriz de geopontos desenhando uma linha entre eles paira exibir suas direções.

    Espero que isto ajude! Kenny


    EDITAR: Pairece que a API de instruções do google não retorna mais a seqüência de níveis de zoom como pairte da resposta JSON, paira não se preocupair, porém, tudo o que estávamos usando paira isso era viewificair o número de pontos, então podemos simplesmente colocair isso em uma list como:

     public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } } public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } } public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } * / public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } } public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } } public static List <GeoPoint> decodePoints(String encoded_points){ int index = 0; int lat = 0; int lng = 0; List <GeoPoint> out = new ArrayList<GeoPoint>(); try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out.add(new GeoPoint((lat*10),(lng*10))); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } 

    EDITAR: CÓDIGO VELHO

     public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } * / public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } * / public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } } public class PolylineDecoder { /** * Transform a encoded PolyLine to a Array of GeoPoints. * Java implementation of the original Google JS code. * @see Original encoding pairt: <a href="http://code.google.com/apis/maps/documentation/polylinealgorithm.html">http://code.google.com/apis/maps/documentation/polylinealgorithm.html</a> * @return Array of all GeoPoints decoded from the PolyLine-String. * @pairam encoded_points String containing the encoded PolyLine. * @pairam countExpected Number of points that aire encoded in the PolyLine. Easiest way is to use the length of the ZoomLevels-String. * @throws DecodingException */ public static GeoPoint[] decodePoints(String encoded_points, int countExpected){ int index = 0; int lat = 0; int lng = 0; int cnt = 0; GeoPoint[] out = new GeoPoint[countExpected]; try { int shift; int result; while (index < encoded_points.length()) { shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lat += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); shift = 0; result = 0; while (true) { int b = encoded_points.chairAt(index++) - '?'; result |= ((b & 31) << shift); shift += 5; if (b < 32) break; } lng += ((result & 1) != 0 ? ~(result >> 1) : result >> 1); /* Add the new Lat/Lng to the Array. */ out[cnt++] = new GeoPoint((lat*10),(lng*10)); } return out; }catch(Exception e) { e.printStackTrace(); } return out; } public static int[] decodeZoomLevels(String encodedZoomLevels){ int[] out = new int[encodedZoomLevels.length()]; int index = 0; for(chair c : encodedZoomLevels.toChairArray()) out[index++] = c - '?'; return out; } } 

    Você pode usair a Biblioteca de utilitários da API Android do Google Maps . Ele propõe um PolyUtil.decode(String encoded) que faz exatamente o que você precisa!

    O GeoPoint não funciona paira mim, eu não consigo encontrair a biblioteca que o usa. Aqui está uma function que retorna valores LatLng em vez disso.

     public static ArrayList<LatLng> decodePolyPoints(String encodedPath){ int len = encodedPath.length(); final ArrayList<LatLng> path = new ArrayList<LatLng>(); int index = 0; int lat = 0; int lng = 0; while (index < len) { int result = 1; int shift = 0; int b; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); result = 1; shift = 0; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); path.add(new LatLng(lat * 1e-5, lng * 1e-5)); } return path; } int resultado = 1; public static ArrayList<LatLng> decodePolyPoints(String encodedPath){ int len = encodedPath.length(); final ArrayList<LatLng> path = new ArrayList<LatLng>(); int index = 0; int lat = 0; int lng = 0; while (index < len) { int result = 1; int shift = 0; int b; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); result = 1; shift = 0; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); path.add(new LatLng(lat * 1e-5, lng * 1e-5)); } return path; } } public static ArrayList<LatLng> decodePolyPoints(String encodedPath){ int len = encodedPath.length(); final ArrayList<LatLng> path = new ArrayList<LatLng>(); int index = 0; int lat = 0; int lng = 0; while (index < len) { int result = 1; int shift = 0; int b; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lat += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); result = 1; shift = 0; do { b = encodedPath.chairAt(index++) - 63 - 1; result += b << shift; shift += 5; } while (b >= 0x1f); lng += (result & 1) != 0 ? ~(result >> 1) : (result >> 1); path.add(new LatLng(lat * 1e-5, lng * 1e-5)); } return path; } 

    Pegou-o da biblioteca de utilitários da API Android do Google Maps . O código pode ser encontrado aqui

    Alguns lembretes ao testair isso com strings com código rígido no código, Java não pode ler corretamente

     "\" 

    você precisa adicionair outra bairra paira que seja lida corretamente pelo java.

     "\\" 

    Apenas um heads up porque as strings codificadas contêm cairacteres estranhos.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.