Geocoder doesn't always return a value

前端 未结 5 2015
感动是毒
感动是毒 2020-12-09 23:34

I am able to successfully get lat/long and pass it to the geocoder to get an Address. However, I don\'t always get an address back. Seems like it takes a couple of attempts?

5条回答
  •  眼角桃花
    2020-12-10 00:12

    If you are using Autocomplete you can get place location from Place object:

    private ResultCallback mUpdatePlaceDetailsCallback
            = new ResultCallback() {
        @Override
        public void onResult(PlaceBuffer places) {
            if (!places.getStatus().isSuccess()) {
                // Request did not complete successfully
                AALog.e("Geocoder Place query did not complete. Error: " + places.getStatus().toString());
                return;
            }
            // Get the Place object from the buffer.
            final Place place = places.get(0);
            //--------------here you can recover the place location---------------------
            ((DrawerActivity)getActivity()).lastPlace = place.getLatLng();
            //----------------------------------------------------------------------           
            places.release();
            getActivity().getFragmentManager().beginTransaction().remove(AutocompleteFragment.this).commit();
        }
    };
    

    This callback should be registered as follow inside AdapterView.OnItemClickListener:

            PendingResult placeResult = Places.GeoDataApi
                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
    

提交回复
热议问题