1 回答
TA贡献1784条经验 获得超7个赞
我测试了我的数据库并发现了发生更新的情况。下面的代码包含更新的 placeID、删除的 placeID 和仍然有效的 palceID,以便进行测试。
ArrayList<String> placeIDsList = new ArrayList<>();
placeIDsList.add("ChIJTaKjynxesBQREvi1CU5QUFg");
placeIDsList.add("EjhDdW1odXJpeWV0IE1haGFsbGVzaSwgVXp1biBTay4sIEV6aW5lL8OHYW5ha2thbGUsIFR1cmtleSIuKiwKFAoSCakQkmN8XrAUEVkLpNK_F4IJEhQKEgmFzKyYe16wFBGSjU7F2ooIIg");
placeIDsList.add("hIJy9YVxdxpsBQRq0-xUVJdZQ8");
// Specify the fields to return (in this example all fields are returned).
List<Place.Field> placeFields = Arrays.asList(Place.Field.ID);
for (String plc : placeIDsList ) {
// Construct a request object, passing the place ID and fields array.
FetchPlaceRequest request = FetchPlaceRequest.builder(plc, placeFields).build();
Log.e(TAG,"request for place with ID = " + plc);
placesClient.fetchPlace(request).addOnSuccessListener((response) -> {
Place place = response.getPlace();
if (!plc.equals(place.getId())) {
Log.e(TAG,"placeID renewed");
Log.e(TAG,"placeID old = " + plc);
Log.e(TAG,"placeID new = " + place.getId());
} else {
Log.e(TAG, "Place found: " + place.getId());
}
}).addOnFailureListener((exception) -> {
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
int statusCode = apiException.getStatusCode();
// Handle error with given status code.
Log.e(TAG, "Place with ID "+plc+" not found");
Log.e(TAG, "Exception message is :" + exception.getMessage());
Log.e(TAG, "Status code = " + statusCode);
}
});
}
输出是
E/MapsActivity: request for place with ID = ChIJTaKjynxesBQREvi1CU5QUFg
E/MapsActivity: request for place with ID = jhDdW1odXJpeWV0IE1haGFsbGVzaSwgVXp1biBTay4sIEV6aW5lL8OHYW5ha2thbGUsIFR1cmtleSIuKiwKFAoSCakQkmN8XrAUEVkLpNK_F4IJEhQKEgmFzKyYe16wFBGSjU7F2ooIIg
E/MapsActivity: request for place with ID = hIJy9YVxdxpsBQRq0-xUVJdZQ8
E/MapsActivity: placeID renewed
E/MapsActivity: placeID old = EjhDdW1odXJpeWV0IE1haGFsbGVzaSwgVXp1biBTay4sIEV6aW5lL8OHYW5ha2thbGUsIFR1cmtleSIuKiwKFAoSCakQkmN8XrAUEVkLpNK_F4IJEhQKEgmFzKyYe16wFBGSjU7F2ooIIg
E/MapsActivity: placeID new = Ei5DdW1odXJpeWV0LCBVenVuIFNrLiwgRXppbmUvw4dhbmFra2FsZSwgVHVya2V5Ii4qLAoUChIJqRCSY3xesBQRWQuk0r8XggkSFAoSCYXMrJh7XrAUEZKNTsXaiggi
E/MapsActivity: Place with ID hIJy9YVxdxpsBQRq0-xUVJdZQ8 not found
E/MapsActivity: Exception message is :9012: INVALID_REQUEST
E/MapsActivity: Status code = 9012
E/MapsActivity: Place found: ChIJTaKjynxesBQREvi1CU5QUFg
似乎是status code 9102找不到地方。
添加回答
举报