Fail to obtain specific Place from PlaceBuffer

泪湿孤枕 提交于 2019-12-03 12:58:06

Add condition && places.getCount() > 0

Example from documentation:

Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
                 .setResultCallback(new ResultCallback<PlaceBuffer>() {
        @Override
        public void onResult(PlaceBuffer places) {
            if (places.getStatus().isSuccess() && places.getCount() > 0) {
            final Place myPlace = places.get(0);
            Log.i(TAG, "Place found: " + myPlace.getName());
        } else {
            Log.e(TAG, "Place not found");
        }
        places.release();
    }
});

Need places.getCount() check as well. Please refer here https://developers.google.com/places/android-api/place-details

I am also having this same problem.

I get Place ID: ChIJD1eejrW35zsRDFfkT-PSbm4 from item.getPlaceId() method, but when I do Reverse Geocoding by Place ID, I do not get any results.

There may be many places that returns the same result as this, so I hope Google recognizes this issue.

But for now I have done this:

/**
 * Callback for results from a Places Geo Data API query that shows the first place result in
 * the details view on screen.
 */
private ResultCallback<PlaceBuffer> fromPlaceResultCallback = new ResultCallback<PlaceBuffer>() {
    @Override
    public void onResult(@NonNull PlaceBuffer places) {
        if (!places.getStatus().isSuccess()) {
            places.release();
            return;
        }
        // Get the Place object from the buffer.
        if(places.getCount() > 0) {
            // Got place details
            Place place = places.get(0);
            // Do your stuff
        } else {
            // No place details 
            Toast.makeText(SelectLocation.this, "Place details not found.", Toast.LENGTH_LONG).show();
        }
        places.release();
    }
};
Srilaxmi Kanna

This happened to me if placeId was wrong/invalid in the call

Places.GeoDataApi.getPlaceById(((MainActivity) getActivity()).mGoogleApiClient, placeId);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!