取照片的车身响应
问题描述:
String photoReference = imageDataObject.getPhotoReference();
String width = imageDataObject.getWidth();
String height = imageDataObject.getHeight();
ApiInterface apiServicePhoto = ApiClient.getClient(GlobalConstant.BASE_URL_PHOTO).create(ApiInterface.class);
Call<ResponseBody> callPhoto = apiServicePhoto.getSinglePhoto(GlobalConstant.MAX_WIDTH_IMAGE, photoReference, GlobalConstant.API_KEY);
callPhoto.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.e(TAG, "onResponse: " + response);
if (response.isSuccessful()) {
if (response.body() != null) {
Log.e(TAG, "onResponse: ");
}
Log.e(TAG, "onResponse: " + response.body());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e(TAG, "onFailure: ");
}
});
// API接口取照片的车身响应
@GET("photo")
Call<ResponseBody> getSinglePhoto(@Query("maxwidth") Integer maxwidth, @Query("photoreference") String photoreference, @Query("key") String key);
// API客户端
public class ApiClient {
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrlRestro) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrlRestro)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
//基本URL
public static final String BASE_URL_PHOTO = "https://maps.googleapis.com/maps/api/place/";
我在尝试克这个代码,但我无法得到任何响应的身体。身体总是空。有什么方法可以使用照片参考获取照片。
预先感谢您
答
至于滑翔是为你工作的罚款,我在这里张贴的代码。
ImageView ivPhoto = (ImageView) findViewById(R.id.ivPhoto);
String url = "https://maps.googleapis.com/maps/api/place/photo" +
"?maxwidth=400" +
"&photoreference=CnRtAAAATLZNl354RwP_9UKbQ_5Psy40texXePv4oAlgP4qNEkdIrkyse7rPXYGd9D_Uj1rVsQdWT4oRz4QrYAJNpFX7rzqqMlZw2h2E2y5IKMUZ7ouD_SlcHxYq1yL4KbKUv3qtWgTK0A6QbGh87GB3sscrHRIQiG2RrmU_jF4tENr9wGS_YxoUSSDrYjWmrNfeEHSGSc3FyhNLlBU" +
"&key=AIzaSyAfDHQhe4fmz5FAitOnTjrOFPesb88GXFE";
Glide.with(this)
.load(url)
.into(ivPhoto);
确保在开发人员控制台中启用了场所API。或使用Glide/Picasso进行图像下载 –
@MuraliPrajapati是的,在开发人员控制台中启用了位置API。我正在使用毕加索进行下载。但是响应主体包含空值。如果得到一个示例代码,那么也很好。谢谢!! –
我在postman中试过这个API,它在那里工作的很好。使用谷歌在这里给出的photoreference:https://developers.google.com/places/web-service/photos –