问题描述
我正在开发一个向用户显示其所在地区不同场所的应用程序,为此,我正在使用google place API。我将所有结果存储在ArrayList中,但是由于某些原因,将它们添加到ArrayList的代码未运行。知道可能是什么原因吗?作为参考,我的代码的相关部分如下:
private void handleAutoCompleteRequest(FindAutocompletePredictionsRequest request) {
// Create a new Places client instance.
PlacesClient placesClient = Places.createClient(this);
placesClient.findAutocompletePredictions(request).addOnSuccessListener((response) -> {
for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
Log.d("PLACEID",prediction.getPlaceId());
Log.d("PLACENAME",prediction.getPrimaryText(null).toString());
placeID = prediction.getPlaceId();
placeName = prediction.getPrimaryText(null).toString();
// Define a Place ID.
final String placeId = placeID;
// Specify the fields to return.
final List<Place.Field> placeFields = Arrays.asList(Place.Field.ID,Place.Field.NAME,Place.Field.ADDRESS,Place.Field.BUSInesS_STATUS,Place.Field.rating,Place.Field.PHOTO_MetaDATAS);
// Construct a request object,passing the place ID and fields array.
final FetchPlaceRequest request1 = FetchPlaceRequest.newInstance(placeId,placeFields);
placesClient.fetchPlace(request1).addOnSuccessListener((response1) -> {
Place place = response1.getPlace();
Log.d("name","Place found: " + place.getName());
Log.d("address","Place found: " + place.getAddress());
Log.d("hours","Place found: " + place.getBusinessstatus());
String statusstring = String.valueOf(place.getBusinessstatus());
String ratingString = String.valueOf(place.getrating());
Log.d("placeStatus",statusstring);
Log.d("placerating",ratingString);
//PHOTOS///////////////////////////////////////////
// Get the photo Metadata.
final List<PhotoMetadata> Metadata = place.getPhotoMetadatas();
if (Metadata == null || Metadata.isEmpty()) {
Log.w("Metadatanull","No photo Metadata.");
return;
}
final PhotoMetadata photoMetadata = Metadata.get(0);
// Get the attribution text.
final String attributions = photoMetadata.getAttributions();
// Create a FetchPhotoRequest.
final FetchPhotoRequest photoRequest = FetchPhotoRequest.builder(photoMetadata)
.setMaxWidth(500) // Optional.
.setMaxHeight(300) // Optional.
.build();
placesClient.fetchPhoto(photoRequest).addOnSuccessListener((fetchPhotoResponse) -> {
placePhoto = fetchPhotoResponse.getBitmap();
Log.d("isthisrunning","yesitsrunning");
TenderSuggestion mySuggestion = new TenderSuggestion(place.getAddress(),place.getName(),place.getId(),statusstring,ratingString,placePhoto);
TenderSuggestions.add(mySuggestion);
Log.d("testArrayList","added");
for (int i = 0; i < TenderSuggestions.size(); i++) {
String master = TenderSuggestions.get(i).getSuggestionName();
for (int p = 0; p < TenderSuggestions.size(); p++) {
if (p != i) {
String subject = TenderSuggestions.get(p).getSuggestionName();
if (master.equals(subject)) {
TenderSuggestions.remove(p);
i--;
}
}
}
}
NUM_PAGES = TenderSuggestions.size();
Log.d("Arraylength1",String.valueOf(TenderSuggestions.size()));
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
final ApiException apiException = (ApiException) exception;
Log.e("placeError","Place not found: " + exception.getMessage());
final int statusCode = apiException.getStatusCode();
// Todo: Handle error with given status code.
}
});
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
final ApiException apiException = (ApiException) exception;
Log.d("error","Place not found: " + exception.getMessage());
final int statusCode = apiException.getStatusCode();
// Todo: Handle error with given status code.
}
Log.d("error","Place not found: " + exception.getMessage());
});
}
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.d("ERROR","Place not found: " + apiException.getStatusCode());
}
});
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)