1

this is the request format

https://roads.googleapis.com/v1/nearestRoads?parameters&key=YOUR_API_KEY

here i need to pass latitude and longitude as parameter points, something like this

https://roads.googleapis.com/v1/nearestRoads?points=60.170880,24.942795|60.170879,24.942796|60.170877,24.942796&key=YOUR_API_KEY

i tried to pass it like

  @POST("nearestRoads?points&key=my_api_key")
Call<SnappedPoints> getNearestRoad(@FieldMap Double map);

by calling

Call<SnappedPoints> call = retrofitClientMap.getNearestRoad(stringStringMap.put(latLng3.latitude,latLng3.longitude));

but it shows an illegal exception , can any one help have an idea to solve it

Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33
jin
  • 53
  • 8
  • isn't `@Query` used for `@GET` method ? – Ali Ahmed Oct 29 '18 at 07:38
  • my mistake I thought it was @GET method. – karan Oct 29 '18 at 07:41
  • 1
    are you missing `@FormUrlEncoded` in your code or only in question. – karan Oct 29 '18 at 07:44
  • @POST("nearestRoads?points=9.994932,76.288885&key=my_key") Call getNearestRoad(); this should be the format but have to pass that values 9.994932,76.288885 inside function getNearestRoad() – jin Oct 29 '18 at 07:55
  • An illegal exception? Do you mean an illegal argument [exception](https://stackoverflow.com/a/15209875/1008011)? If so, it's probably because you are passing in the wrong argument to getNearestRoad(...). You are declaring @FieldMap with a `Double` (object) but when calling, you are passing in a `double` (primitive): stringStringMap.put(60.170880,24.942795) – chornge Oct 30 '18 at 20:03

2 Answers2

0

Have you tried something like this

@POST("nearestRoads?key=my_api_key")
Call<SnappedPoints> getNearestRoad(@Field("points") String points);

then pass your points as String to this method

Ali Ahmed
  • 2,130
  • 1
  • 13
  • 19
0

i got it by calling api service like

 @POST("nearestRoads?key=my_api_key")
    // Call<MySnappedPoints> getNearestRoad();
Call<MySnappedPoints> getNearestRoad(@Query("points") String points);

calling it by

 String test = Double.toString(mGoogleMap.getCameraPosition().target.latitude) + "," + Double.toString(mGoogleMap.getCameraPosition().target.longitude);
    Call<MySnappedPoints> call = retrofitClientMap.getNearestRoad(test);
jin
  • 53
  • 8