Java google places api:placesClient.findAutocompletePredictions返回任务失败

Java google places api:placesClient.findAutocompletePredictions返回任务失败,java,android,android-studio,google-maps,google-places-api,Java,Android,Android Studio,Google Maps,Google Places Api,我使用placesClient.findAutocompletePredictions返回位置建议,将它们设置为我的搜索栏,但是当我使用下面的函数时,任务总是失败。为什么会这样呢?是从api键,但我启用了places api!!。结果始终为“预测获取任务未成功” @覆盖 public void onTextChanged(字符序列、int start、int before、int count){ AutocompleteSessionToken=AutocompleteSessionToken.

我使用placesClient.findAutocompletePredictions返回位置建议,将它们设置为我的搜索栏,但是当我使用下面的函数时,任务总是失败。为什么会这样呢?是从api键,但我启用了places api!!。结果始终为“预测获取任务未成功”

@覆盖
public void onTextChanged(字符序列、int start、int before、int count){
AutocompleteSessionToken=AutocompleteSessionToken.newInstance();
FindAutocompletePredictionsRequest predictionsRequest=FindAutocompletePredictionsRequest.builder()
.setCountry(“sa”)
.setTypeFilter(TypeFilter.ADDRESS)
.setSessionToken(令牌)
.setQuery(s.toString())
.build();
placesClient.findautoCompletePredictionsRequest.addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
FinDautoCompletePredictionResponse PredictionResponse=task.getResult();
if(predictionsResponse!=null){
predictionList=PredictionResponse.getAutocompletePredictions();
列表建议列表=新建ArrayList();
对于(int i=0;i
您是否启用了项目的计费功能?是否正在添加项目的API密钥?有限制吗?请发布你的日志。我还没有启用计费功能,有没有办法不用提供我的信用卡信息就可以做到这一点?你需要提供一些计费信息。查看您可以在此处添加的可用付款方式,若要开始,请查看此链接@evan I enabled billing相同的问题@evan你所说的受限是什么意思?你在你的项目上启用了计费功能吗?是否正在添加项目的API密钥?有限制吗?请发布你的日志。我还没有启用计费功能,有没有办法不用提供我的信用卡信息就可以做到这一点?你需要提供一些计费信息。查看您可以在此处添加的可用付款方式,若要开始,请查看此链接@evan I enabled billing相同的问题@埃文你说的限制是什么意思?
 @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");
                                                                }
                                                            }
                                                        });
                                                    }