Google Maps Places Api错误:状态码9011 |安卓

问题描述

我正在尝试在Android应用中使用Places API。但是我收到了错误状态代码9011。根据文档(https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/net/PlacesStatusCodes),此错误代码表示由于授权问题导致操作失败。在帐户上启用了结算,并且启用了Maps and Places API。 Maps API正在该应用上运行。

代码如下:

if (!Places.isInitialized())
             Places.initialize(getApplicationContext(),getResources().getString(R.string.map_api_key));
 AutocompleteSessionToken token = AutocompleteSessionToken.newInstance();
        // Create a RectangularBounds object.

        // Use the builder to create a FindAutocompletePredictionsRequest.
        FindAutocompletePredictionsRequest request = FindAutocompletePredictionsRequest.builder()
                // Call either setLocationBias() OR setLocationRestriction().
                //.setLocationRestriction(bounds)
                .setCountry("ng")//Nigeria
                .setTypeFilter(TypeFilter.ADDRESS)
                .setSessionToken(token)
                .setQuery("SaltLak")
                .build();


        placesClient.findAutocompletePredictions(request).addOnSuccessListener(response -> {
          StringBuilder  mResult = new StringBuilder();
            for (AutocompletePrediction prediction : response.getAutocompletePredictions()) {
                mResult.append(" ").append(prediction.getFullText(null) + "\n");
                Log.i(TAG,prediction.getPlaceId());
                Log.i(TAG,prediction.getPrimaryText(null).toString());
            }
            Log.i(TAG,mResult.toString());
        }).addOnFailureListener((exception) -> {
            if (exception instanceof ApiException) {
                ApiException apiException = (ApiException) exception;
                Log.e(TAG,"Place not found: " + apiException.getStatusCode());
            }
        });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)