I am new with Retrofit 2, and am trying to integrate a Google Place API in my App. My Question is how to move forward with this kind of Dynamic URL while using Retrofit 2.0.
URL:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input="{Place Name}"&location="{Lat,long}"&key="{API KEY}"
My Model Classes Name are:
1) PlaceAutoComplete
2) PlacePredictions
public class PlaceAutoComplete {
private String place_id;
private String description;
public String getPlaceDesc() {
return description;
}
public void setPlaceDesc(String placeDesc) {
description = placeDesc;
}
public String getPlaceID() {
return place_id;
}
public void setPlaceID(String placeID) {
place_id = placeID;
}
}
AND
public class PlacePredictions {
public ArrayList<PlaceAutoComplete> getPlaces() {
return predictions;
}
public void setPlaces(ArrayList<PlaceAutoComplete> places) {
this.predictions = places;
}
private ArrayList<PlaceAutoComplete> predictions;
}
And I have create the WebServiceCall.java class for Retrofit, This is my Code
public class WebServiceCall {
private static WebServiceCall webServiceCall;
public RetrofitService retrofitService;
private String currentDateTimeString;
public WebServiceCall() {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
if (Boolean.parseBoolean("true")) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
clientBuilder.connectTimeout(100000, TimeUnit.MILLISECONDS);
clientBuilder.addInterceptor(httpLoggingInterceptor);
}
retrofitService = new Retrofit.Builder()
.baseUrl("https://maps.googleapis.com/maps/api/place/autocomplete/json")
.client(clientBuilder.build())
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(RetrofitService.class);
currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
}
public static WebServiceCall getInstance() {
if (webServiceCall == null) {
webServiceCall = new WebServiceCall();
}
return webServiceCall;
}
}
And I am using this Interface in Call the URL: but I unable to move forward with this.
public interface RetrofitService {
@GET("?input=")
Call<PlaceAutoComplete> getInput(@Url String url);
}
I been search in the google and StackOverflow, but not make me understand. A detailed explanation will be highly appreciable.
Thank you.