1

i used placesClient.findAutocompletePredictions to return location suggestions to set them my search bar, but when i use this functions below, task is always insuccessul why is that, is it from the api key but i enabled places api!!. Result always "prediction fetching task unsuccessful"

 @Override
                                                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                                                        AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
                                                        FindAutocompletePredictionsRequest predictionsRequest = FindAutocompletePredictionsRequest.builder()
                                                                .setCountry("sa")
                                                                .setTypeFilter(TypeFilter.ADDRESS)
                                                                .setSessionToken(token)
                                                                .setQuery(s.toString())
                                                                .build();
                                                        placesClient.findAutocompletePredictions(predictionsRequest).addOnCompleteListener(new OnCompleteListener<FindAutocompletePredictionsResponse>() {
                                                            @Override
                                                            public void onComplete(@NonNull Task<FindAutocompletePredictionsResponse> task) {
                                                                if (task.isSuccessful()) {
                                                                    FindAutocompletePredictionsResponse predictionsResponse = task.getResult();
                                                                    if (predictionsResponse != null) {
                                                                        predictionList = predictionsResponse.getAutocompletePredictions();
                                                                        List<String> suggestionsList = new ArrayList<>();
                                                                        for (int i = 0; i < predictionList.size(); i++) {
                                                                            AutocompletePrediction prediction = predictionList.get(i);
                                                                            suggestionsList.add(prediction.getFullText(null).toString());
                                                                        }
                                                                        materialSearchBar.updateLastSuggestions(suggestionsList);
                                                                        if (!materialSearchBar.isSuggestionsVisible()) {
                                                                            materialSearchBar.showSuggestionsList();
                                                                        }
                                                                    }
                                                                } else {
                                                                    Log.i("mytag", "prediction fetching task unsuccessful");
                                                                }
                                                            }
                                                        });
                                                    }

Aymen Ncr
  • 11
  • 3
  • Have you enabled billing on your project? Are you adding your project's API key? Is it restricted? Please post your logcat. – evan Sep 11 '20 at 14:23
  • i haven't enabled billing, is there a way to do it without giving my credit card info's – Aymen Ncr Sep 12 '20 at 14:39
  • You need to give some kind of billing information. See available payment methods you can add here https://cloud.google.com/billing/docs/how-to/payment-methods#available_payment_methods and to get started check out this link https://developers.google.com/maps/gmp-get-started#create-billing-account – evan Sep 16 '20 at 16:19
  • @evan I enabled billing same problem!! – Aymen Ncr Oct 18 '20 at 12:43
  • @evan what you mean by restricted? – Aymen Ncr Oct 18 '20 at 13:03

0 Answers0