Fala jovem, muitíssimo obrigado por responder. Porém, ainda não consegui executar
Fiz algumas alterações (removi o ProgressBar)
private Polyline direction;
private class ParserTask extends AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {
@Override
protected List<List<HashMap<String, String>>> doInBackground(String... strings) {
List<List<HashMap<String, String>>> routes = null;
try {
JSONObject jsonObject = new JSONObject(strings[0]);
DirectionJSONParser parser = new DirectionJSONParser();
routes = parser.parse(jsonObject);
} catch (JSONException ex) {
frmDados.print("ParserTask:doInBg { "+ex.getMessage()+" } ");
}
return routes;
}
//
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> lists) {
ArrayList points = null;
PolylineOptions polylineOptions = null;
//
for (int i = 0; i < lists.size(); i++) {
points = new ArrayList();
polylineOptions = new PolylineOptions();
List<HashMap<String, String>> path = lists.get(i);
for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);
//Aqui gera o caminho. Exemplo: Vire a esquerda, direita, etc...
double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);
points.add(position);
}
polylineOptions.addAll(points);
polylineOptions.width(10);
polylineOptions.color(R.drawable.ic_launcher_background);
polylineOptions.geodesic(true);
}
direction = mMap.addPolyline(polylineOptions);
}
}
E no meu código que desenha a rota(seria o equivalente ao seu método getDirection, mas somente a parte do onResponse), coloquei o newParser
public void desenhaRota(Response response) {
try {
//
if (response != null) {
new ParserTask().execute(response.body().string());
//
......
Porém, está aparecendo
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
Sabe dizer o que pode estar causando isso?