• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在位置自动完成片段PLACES_API_ACCESS_NOT_CONFIGURED

用户头像
it1352
帮助1

问题说明

我在使用Android Google Places API时遇到问题-自动完成功能.我使用了与Android Google Maps API相同的密钥,但它不是开放空间片段.它仅显示地图,但是在打开位置自动完成片段时会打开并自动关闭,并显示PLACES_API_ACCESS_NOT_CONFIGURED错误.请帮助我解决此问题,并显示处理此问题的权利.这是我的清单XML:

I'm having problems with Android Google Places API - autocomplete feature. I use the same key that I used for Android Google Maps API but it is not open place fragment. Its only show Maps but when open a Place Autocomplete Fragment but its open and automatically close and show PLACES_API_ACCESS_NOT_CONFIGURED error. Please help me out to this issue and show the right to handle the issue. Here My Manifest XML:

  <meta-data
        android:name="com.谷歌.android.geo.API_KEY"
        android:value="AIzaSyARQ78yaNEJH12aJLM1Y-112WY12p95ZOEGI"/>

这里是开放位置AutocolmpleteFragment的我的代码:

And Here My Code for open Place AutocolmpleteFragment:

 try {
                Intent intent =
                        new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN)
                                .build(getActivity());
                startActivityForResult(intent, 1);

            } catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {

                // TODO: Handle the error.

            }

还有这里我获得位置响应的代码:

And Here My code for getting a place response:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        if (resultCode ==RESULT_OK) {
            Place place = PlaceAutocomplete.getPlace(getActivity(), data);
            onPlaceSelected(place,1);
            bar.setVisibility(View.GONE);
            autoCompleteTextViewPickup.setFocusable(true);
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {

            Status status = PlaceAutocomplete.getStatus(getActivity(), data);
            this.onError(status,1);
            bar.setVisibility(View.GONE);
            autoCompleteTextViewPickup.setFocusable(true);
        }
    }

正确答案

#1

我遇到了同样的问题,但是我已经能够解决它.

I was having the same problem but i have been able to fix it.

问题是Android的Places SDK的Google Play服务版本(在Google Play服务16.0.0中)已于2019年1月29日弃用,并将于2019年7月29日关闭. 而且,如果您在谷歌 API控制台下进行检查,则它只有PLACES API,再也没有像PLACES SDK FOR ANDROID这样的东西了.

The problem is that The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. And if you check under the 谷歌 API console, it only have the PLACES API and there is nothing like PLACES SDK FOR ANDROID anymore.

在应用程序级build.gradle文件的依赖项部分,为新的SDK客户端库添加依赖项,如以下示例所示:

In the dependencies section of your app-level build.gradle file, add a dependency for the new SDK client library, as shown in the following example:

implementation 'com.谷歌.android.libraries.places:places:1.0.0'

然后,将其初始化.

// Add an import statement for the client library.
import com.谷歌.android.libraries.places.api.Places;

...

// Initialize Places.
Places.initialize(getApplicationContext(), apiKey);

// Create a new Places client instance.
PlacesClient placesClient = Places.createClient(this);

程序化自动完成

对自动完成功能进行了以下更改: PlaceAutocomplete被重命名为Autocomplete. PlaceAutocomplete.getPlace重命名为Autocomplete.getPlaceFromIntent. PlaceAutocomplete.getStatus重命名为Autocomplete.getStatusFromIntent. 将PlaceAutocomplete.RESULT_ERROR重命名为AutocompleteActivity.RESULT_ERROR(自动完成片段的错误处理未更改).

The following changes were made to autocomplete: PlaceAutocomplete is renamed to Autocomplete. PlaceAutocomplete.getPlace is renamed to Autocomplete.getPlaceFromIntent. PlaceAutocomplete.getStatus is renamed to Autocomplete.getStatusFromIntent. PlaceAutocomplete.RESULT_ERROR is renamed to AutocompleteActivity.RESULT_ERROR (error handling for the autocomplete fragment has NOT changed).

如果您像我的案例一样使用自动填充小部件,则可以使用它.

If you are using the autocomplete widget like my case you can use this.

<fragment
  android: 
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:name=
"com.谷歌.android.libraries.places.widget.AutocompleteSupportFragment"
  />

然后初始化位置

/**
 * Initialize Places. For simplicity, the API key is hard-coded. In a production
 * environment we recommend using a secure mechanism to manage API keys.
 */
if (!Places.isInitialized()) {
    Places.initialize(getApplicationContext(), "YOUR_API_KEY");
}

// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
        getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);

autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
    @Override
    public void onPlaceSelected(Place place) {
        // TODO: Get info about the selected place.
        Log.i(TAG, "Place: "   place.getName()   ", "   place.getId());
    }

    @Override
    public void onError(Status status) {
        // TODO: Handle the error.
        Log.i(TAG, "An error occurred: "   status);
    }
});

在此处查看更多信息

迁移到New Place SDK

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcciekg
系列文章
更多 icon
同类精品
更多 icon
继续加载