2

Hi I am fetching current location detail using google place api.

   List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME, Place.Field.LAT_LNG);
        FindCurrentPlaceRequest request =
                FindCurrentPlaceRequest.builder(placeFields).build();

        mPlaceDetectionClient = Places.createClient(this);
        Task<FindCurrentPlaceResponse> placeResponse = mPlaceDetectionClient.findCurrentPlace(request);


        placeResponse.addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                FindCurrentPlaceResponse response = task.getResult();

                    List<Place> placesList = new ArrayList<Place>();

                assert response != null;
                for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {
                        placesList.add(placeLikelihood.getPlace());
                    }
                    showAddPropertyNameDialog(AppStringConstants.ADD_NEW_STORE_TAG, placesList.get(0));
                hideLoader();
            } else {
                showDialog(getString(R.string.find_location_fail_msg), "", new DialogType(DialogType.DIALOG_MESSAGE));
            }

        });

But It always return location timeout

com.google.android.gms.common.api.ApiException: 15: Location timeout.

I have migrated my code to new apis as below. https://developers.google.com/places/android-sdk/current-place

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rajneesh Shukla
  • 1,048
  • 13
  • 21
  • Did you find a solution for this? Try updating to the latest version [com.google.android.libraries.places 2.1.0](https://mvnrepository.com/artifact/com.google.android.libraries.places/places/2.1.0) – Anoop M Maddasseri Dec 12 '19 at 11:17
  • are you asking for solution or giving a solution? – Rajneesh Shukla Dec 12 '19 at 17:52
  • What I discovered is that if you open the maps application and get the current location, the places client will work for while. I manage to fix this permanently (though not elegantly) by first getting the current location with FusedLocationProviderClient each time before invoking the Places client. It's strange because you would think that the Places client uses FusedLocationProviderClient under the hood – codeman Oct 12 '21 at 15:30

0 Answers0