Хочу проложить маршрут между двумя точками Но выкидывает ошибку, хотя PostMan выдает результат. В чем ошибка?
public void showRoute(LatLng myPosition, LatLng shopId){
from = ""+myPosition.latitude+","+myPosition.longitude;
to = ""+shopId.latitude+","+shopId.longitude;
Log.e("from",String.valueOf(from));
Log.e("to",String.valueOf(to));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://maps.googleapis.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
APIService service = retrofit.create(APIService.class);
service.getRoute(from, to, true, "ru", new Callback<RouteResponse>() {
@Override
public void onResponse(Call<RouteResponse> call, Response<RouteResponse> response) {
//Декодируем маршрут в точки LatLng
List<LatLng> mPoints = PolyUtil.decode(response.body().getPoints());
//Строим полилинию
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.width(4f).color(R.color.colorPrimary);
LatLngBounds.Builder latLngBuilder = new LatLngBounds.Builder();
for(int i = 0;i<mPoints.size();i++){
polylineOptions.add((LatLng)mPoints.get(i));
latLngBuilder.include((LatLng)mPoints.get(i));
}
map.addPolyline(polylineOptions);
int size = getResources().getDisplayMetrics().widthPixels;
LatLngBounds latLngBounds = latLngBuilder.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(latLngBounds,size,size,25);
map.moveCamera(cameraUpdate);
//
//
}
@Override
public void onFailure(Call<RouteResponse> call, Throwable t) {
}
});
Ошибку кидает на строчку service.getRoute(from, to, true, "ru", new Callback<RouteResponse>() {
Log:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.IllegalArgumentException: Unable to create call adapter for class com.example.danilshik.testapplication.models.RouteResponse
for method APIService.getRoute
at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:751)
at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:236)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:161)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:169)
at retrofit2.Retrofit$1.invoke(Retrofit.java:146)
at $Proxy1.getRoute(Native Method)
at com.example.danilshik.testapplication.fragments.ShopInMapWay.showRoute(ShopInMapWay.java:163)
at com.example.danilshik.testapplication.fragments.ShopInMapWay.onMapReady(ShopInMapWay.java:130)
at com.google.android.gms.maps.zzac.zza(Unknown Source)
at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown Source)
at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:326)
at fs.b(:com.google.android.gms.dynamite_dynamitemodulesb@12685005@12.6.85 (000700-197041431):20)
at com.google.android.gms.maps.internal.bg.a(:com.google.android.gms.dynamite_dynamitemodulesb@12685005@12.6.85 (000700-197041431):5)
at com.google.maps.api.android.lib6.impl.be.run(:com.google.android.gms.dynamite_dynamitemodulesb@12685005@12.6.85 (000700-197041431):5)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Could not locate call adapter for class com.example.danilshik.testapplication.models.RouteResponse.
Tried:
* retrofit2.ExecutorCallAdapterFactory
at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:240)
at retrofit2.Retrofit.callAdapter(Retrofit.java:204)
at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:234)
... 22 more
Класс
public class RouteResponse {
public List<Route> routes;
public String getPoints(){
return this.routes.get(0).overviewPolyline.points;
}
class Route{
OverviewPolyline overviewPolyline;
}
class OverviewPolyline{
String points;
}
}
JSON, который приходит в PostMan
{
"geocoded_waypoints": [
{
"geocoder_status": "OK",
"place_id": "ChIJs4CrATw62UMRKg9NqObeA2I",
"types": [
"street_address"
]
},
{
"geocoder_status": "OK",
"place_id": "ChIJcQYIThU62UMRmhKGs-q_q70",
"types": [
"route"
]
}
],
"routes": [
{
"bounds": {
"northeast": {
"lat": 54.7380729,
"lng": 55.9732509
},
"southwest": {
"lat": 54.7329662,
"lng": 55.9581493
}
},
"copyrights": "Картографические данные © 2018 Google",
"legs": [
{
"distance": {
"text": "1,7 км",
"value": 1690
},
"duration": {
"text": "8 мин.",
"value": 470
},
"end_address": "ул. Ивана Якутова, Уфа, Респ. Башкортостан, Россия",
"end_location": {
"lat": 54.73732889999999,
"lng": 55.9581493
},
"start_address": "ул. Мингажева, 160/1, Уфа, Респ. Башкортостан, Россия, 450005",
"start_location": {
"lat": 54.7348831,
"lng": 55.9732509
},
"steps": [
{
"distance": {
"text": "20 м",
"value": 20
},
"duration": {
"text": "1 мин.",
"value": 6
},
"end_location": {
"lat": 54.7347061,
"lng": 55.9732059
},
"html_instructions": "Направляйтесь на <b>юг</b>",
"polyline": {
"points": "_lamIygstI`@F"
},
"start_location": {
"lat": 54.7348831,
"lng": 55.9732509
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "67 м",
"value": 67
},
"duration": {
"text": "1 мин.",
"value": 36
},
"end_location": {
"lat": 54.73477699999999,
"lng": 55.972175
},
"html_instructions": "Поверните <b>направо</b> в сторону <b>ул. Мингажева</b>",
"maneuver": "turn-right",
"polyline": {
"points": "}jamIqgstIEjBG`B"
},
"start_location": {
"lat": 54.7347061,
"lng": 55.9732059
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "91 м",
"value": 91
},
"duration": {
"text": "1 мин.",
"value": 46
},
"end_location": {
"lat": 54.734899,
"lng": 55.9708943
},
"html_instructions": "Поверните <b>налево</b> в сторону <b>ул. Мингажева</b>",
"maneuver": "turn-left",
"polyline": {
"points": "kkamIcastIB@DB@@@@?B@@?H?D?FAJQvAI|@Iv@"
},
"start_location": {
"lat": 54.73477699999999,
"lng": 55.972175
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "0,2 км",
"value": 223
},
"duration": {
"text": "1 мин.",
"value": 64
},
"end_location": {
"lat": 54.7329662,
"lng": 55.9699862
},
"html_instructions": "Поверните <b>налево</b> на <b>ул. Мингажева</b>",
"maneuver": "turn-left",
"polyline": {
"points": "clamIayrtIn@RLFdCv@xB~@bA^"
},
"start_location": {
"lat": 54.734899,
"lng": 55.9708943
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "0,8 км",
"value": 758
},
"duration": {
"text": "2 мин.",
"value": 141
},
"end_location": {
"lat": 54.7349762,
"lng": 55.9589906
},
"html_instructions": "Поверните <b>направо</b> на <b>ул. Революционная</b>",
"maneuver": "turn-right",
"polyline": {
"points": "a`amImsrtIAf@OfACb@SpBc@pGG`AI~@Ef@a@hFKrAOvBI|@QhBALIz@]rDKnAe@`FKxCIdAOXINIJCBSTA??@KHUJ"
},
"start_location": {
"lat": 54.7329662,
"lng": 55.9699862
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "0,4 км",
"value": 369
},
"duration": {
"text": "2 мин.",
"value": 99
},
"end_location": {
"lat": 54.7380729,
"lng": 55.9594288
},
"html_instructions": "На круге сверните на <b>2-й</b> съезд на <b>ул. Цюрупы</b>",
"maneuver": "roundabout-right",
"polyline": {
"points": "slamIunptICCAACAG?GAG@G@MFCBABCFCNAHAJo@d@OTICSEwE}Ai@SOEoA]KE}@[UI"
},
"start_location": {
"lat": 54.7349762,
"lng": 55.9589906
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "0,1 км",
"value": 101
},
"duration": {
"text": "1 мин.",
"value": 31
},
"end_location": {
"lat": 54.73719089999999,
"lng": 55.9590615
},
"html_instructions": "Выполните <b>разворот</b>",
"maneuver": "uturn-left",
"polyline": {
"points": "}_bmImqptITH|@ZJDnA\\"
},
"start_location": {
"lat": 54.7380729,
"lng": 55.9594288
},
"travel_mode": "DRIVING"
},
{
"distance": {
"text": "61 м",
"value": 61
},
"duration": {
"text": "1 мин.",
"value": 47
},
"end_location": {
"lat": 54.73732889999999,
"lng": 55.9581493
},
"html_instructions": "Поверните <b>направо</b> на <b>ул. Ивана Якутова</b><div style=\"font-size:0.9em\">Пункт назначения будет слева</div>",
"maneuver": "turn-right",
"polyline": {
"points": "mzamIcoptI[tD"
},
"start_location": {
"lat": 54.73719089999999,
"lng": 55.9590615
},
"travel_mode": "DRIVING"
}
],
"traffic_speed_entry": [],
"via_waypoint": []
}
],
"overview_polyline": {
"points": "_lamIygstI`@FEjBG`BB@FD@D@Xg@xE|@ZdCv@xB~@bA^Af@SjBw@bKQ`CcA|Mg@pFi@bGe@`FKxCIdAOXSZYZa@TEE[AUHEFGVCTo@d@OT]IaGqB_Bc@iAa@UITHhA`@nA\\[tD"
},
"summary": "ул. Революционная",
"warnings": [],
"waypoint_order": []
}
],
"status": "OK"
}
Статья, по которой делал: https://habr.com/post/275019/
Upd APIService:
@GET ("maps/api/direction/json")
RouteResponse getRoute(
@Query(value = "origin", encoded = false) String position,
@Query(value = "destination",encoded = false) String dectination,
@Query("sensor") boolean sensor,
@Query("language") String language,
Callback<RouteResponse> cb
);
Побробуйте добавить аннотации к моделям, чтобы парсер мог понять как матчить поля в ответе:
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;
}
}
Отсюда https://stackoverflow.com/a/30184220/5892568 + там в ответах есть untility для работы.
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
Нужно нарисовать треугольник на CSSСпособы которые описаны в статьях используют border, визуально они как треугольник, но внутри нельзя поместить...
Пытаюсь сделать так, чтобы на экране было две колонки - левая и праваяВ каждой колонке по таблице
Недавно закончил с основным наполнением своего первого интернет-магазина и решил заняться оптимизациейПроблемы с блокирующими css удалось...