Я успешно внедрил API поиска Google Адресов в одном из моих проектов. Ниже приведен код реализации:
APISERVICE: - @GET ("api / place / nearsearch / json? & Key = GOOGLE_PLACE_API_KEY") Вызовите getNearbyCall (@Query ("YOUR_QUERY_TYPE") ) Тип строки, @Query ("LATITUDE_LONGITUDE") Расположение строки, @Query ("RADIUS_IN_METER") int radius);
RETROFITCLIENT: -
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl("https://maps.googleapis.com/maps/")
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
И мой последний вызов API: -
private void doRequestForGooglePlaceApi(double latitude, double longitude, int locationRadius, String locationType) {
APIService mApiService = RetrofitClient.getClient("https://maps.googleapis.com/maps/").create(APIService.class);
Call<NearbyModel> call = mApiService.getNearbyCall(locationType, latitude + "," + longitude, locationRadius);
call.enqueue(new Callback<NearbyModel>() {
@Override
public void onResponse(Call<NearbyModel> call, Response<NearbyModel> response) {
if (response.isSuccessful() && response.body() != null && response.body().getResults() != null) {
setNearbyAdapter(response.body().getResults());
} else {
Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
}
}
@Override
public void onFailure(Call<NearbyModel> call, Throwable t) {
Globals.showToast(NearbyActivity.this, getString(R.string.msg_something_went_wrong));
}
});
}