Dirección del mapa de Google Api con Retrofit

Quiero dibujar la ruta entre dos Ubicación. Utilicé la biblioteca de adaptación para llamar a la API. No recibí ninguna respuesta. Necesito la polilínea en un ArrayList. ¿Cómo hago eso? Necesita ayuda para crear el GsonAdapter también … Gracias ..

En la actividad `

String base_url = "http://maps.googleapis.com/"; Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .create(); RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(base_url) .setLogLevel(RestAdapter.LogLevel.FULL) .build(); MyApiRequestInterface reqinterface = restAdapter.create(MyApiRequestInterface.class); reqinterface.getJson(fromPosition.latitude + "," + fromPosition.longitude, toPosition.latitude + "," + toPosition.longitude, new Callback<DirectionResults>() { @Override public void success(DirectionResults directionResults, Response response) { Log.i("zacharia", "inside on success" +directionResults.getRoutes().size()); ArrayList<LatLng> routelist = new ArrayList<LatLng>(); if(directionResults.getRoutes().size()>0){ ArrayList<LatLng> decodelist; Route routeA = directionResults.getRoutes().get(0); Log.i("zacharia", "Legs length : "+routeA.getLegs().size()); if(routeA.getLegs().size()>0){ List<Steps> steps= routeA.getLegs().get(0).getSteps(); Log.i("zacharia","Steps size :"+steps.size()); Steps step; Location location; String polyline; for(int i=0 ; i<steps.size();i++){ step = steps.get(i); location =step.getStart_location(); routelist.add(new LatLng(location.getLat(), location.getLng())); Log.i("zacharia", "Start Location :" + location.getLat() + ", " + location.getLng()); polyline = step.getPolyline().getPoints(); decodelist = RouteDecode.decodePoly(polyline); routelist.addAll(decodelist); location =step.getEnd_location(); routelist.add(new LatLng(location.getLat() ,location.getLng())); Log.i("zacharia","End Location :"+location.getLat() +", "+location.getLng()); } } } Log.i("zacharia","routelist size : "+routelist.size()); if(routelist.size()>0){ PolylineOptions rectLine = new PolylineOptions().width(10).color( Color.RED); for (int i = 0; i < routelist.size(); i++) { rectLine.add(routelist.get(i)); } // Adding route on the map mMap.addPolyline(rectLine); markerOptions.position(toPosition); markerOptions.draggable(true); mMap.addMarker(markerOptions); } } @Override public void failure(RetrofitError retrofitError) { System.out.println("Failure, retrofitError" + retrofitError); } });` 

Crear interfaz de actualización

 public interface MyApiRequestInterface { @GET("/maps/api/directions/json") public void getJson(@Query("origin") String origin,@Query("destination") String destination, Callback<DirectionResults> callback);} 

Crear clases de modelo

 public class DirectionResults { @SerializedName("routes") private List<Route> routes; public List<Route> getRoutes() { return routes; }} public class Route { @SerializedName("overview_polyline") private OverviewPolyLine overviewPolyLine; private List<Legs> legs; public OverviewPolyLine getOverviewPolyLine() { return overviewPolyLine; } public List<Legs> getLegs() { return legs; } } public class Legs { private List<Steps> steps; public List<Steps> getSteps() { return steps; } } public class Steps { private Location start_location; private Location end_location; private OverviewPolyLine polyline; public Location getStart_location() { return start_location; } public Location getEnd_location() { return end_location; } public OverviewPolyLine getPolyline() { return polyline; } } public class OverviewPolyLine { @SerializedName("points") public String points; public String getPoints() { return points; } } public class Location { private double lat; private double lng; public double getLat() { return lat; } public double getLng() { return lng; } } 

Crear el método Polyline Decode

 public class RouteDecode { public static ArrayList<LatLng> decodePoly(String encoded) { ArrayList<LatLng> poly = new ArrayList<LatLng>(); int index = 0, len = encoded.length(); int lat = 0, lng = 0; while (index < len) { int b, shift = 0, result = 0; do { b = encoded.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.charAt(index++) - 63; result |= (b & 0x1f) << shift; shift += 5; } while (b >= 0x20); int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); lng += dlng; LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5); poly.add(position); } return poly; } } 
  • ¿Cómo analizar json array con múltiples objetos por gson?
  • Archivo o base de datos? - Mejores prácticas para guardar objetos en dispositivos Android
  • Error json de Android com.google.gson.JsonSyntaxException: java.lang.IllegalStateException
  • Biblioteca Json Parsing Gson de Google: ¿Cuál es la diferencia entre JsonElement y JsonObject?
  • Uso de Gson para analizar subclases con diferentes campos
  • Deserialización de tipos genéricos con GSON
  • Gson NoClassDefFoundError después de que las herramientas ADT y SDK se actualicen a v17
  • Utilizar GSON para analizar un JSON con "clave" dinámica y "valor" en android
  • Retrofit - eliminando algunos caracteres inválidos del cuerpo de respuesta antes de analizarlo como json
  • Cómo analizar Json Array con gson en android
  • Crear objeto de la cadena Gson no funciona
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.