【问题标题】:Google Places API for Android not showing适用于 Android 的 Google Places API 未显示
【发布时间】:2019-09-24 20:11:47
【问题描述】:

我们无法在 Google API 服务列表中看到 适用于 Android 的 Google Places API。我们正在将应用切换到新的 google 帐户,因此我们启用了新帐户中无法找到适用于 Android 的 Google Places API 的所有现有服务。
我们需要在新帐户中启用 Google Places API for Android 以支持现有客户,直到我们进行迁移。
您能帮我们解决这个问题吗?

【问题讨论】:

  • 来自 Google 支持人员的 This answer 似乎表明只有以前使用 Places API 的项目才能访问它,而新项目则不能:请注意,使用 Places API 的老用户适用于 iOS/Android 的 SDK 是唯一在弃用期间仍可以使用地点选择器的 SDK

标签: android google-maps google-play-services google-places-api


【解决方案1】:

根据 Google 新政策“弃用通知:Google Play Services 版本的 Places SDK for Android”

注意:Google Play 服务版本的 Places SDK for Android(在 Google Play 服务 16.0.0 中)自 2019 年 1 月 29 日起弃用,并将于 2019 年 7 月 29 日关闭。新版本的Places SDK for Android 现已推出。我们建议尽快更新到新版本。有关详细信息,请参阅迁移指南。 Google Place Autocomplete

添加 Gradle 依赖项

implementation 'com.google.android.libraries.places:places:1.0.0'

初始化 Place API

Places.initialize(getApplicationContext(), "YOUR_API_KEY");

启动自动完成意图

List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
    Intent intent = new Autocomplete.IntentBuilder(
            AutocompleteActivityMode.OVERLAY, fields)
            .build(this);
    startActivityForResult(intent, 1101);

onActivityResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == request_code) {
        if (resultCode == RESULT_OK) {
            Place place = Autocomplete.getPlaceFromIntent(data);
            Log.i(TAG, "ManishPlace: " + place.getName() + ", " + place.getId());
            txt_search.setText(place.getName());
        } else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
            // TODO: Handle the error.
            Status status = Autocomplete.getStatusFromIntent(data);
            Log.i(TAG, status.getStatusMessage());
        } else if (resultCode == RESULT_CANCELED) {
            // The user canceled the operation.
        }
    }
}

或关注我的 GitHub 教程

Google Place Search GitHub Repository

【讨论】:

  • 目前我们正在迁移到新的 Places API,但同时,我们需要支持现有客户。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-27
  • 1970-01-01
  • 2015-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多