android - Place Picker 启动后自动关闭

标签 android google-places-api google-places

我想显示地点选择器,以便用户可以选择他/她自己选择的位置。但是放置选择器子 Activity 在启动后会自动关闭。我已经多次检查 API key 和其他权限,一切都是正确的。这是所有代码。请帮忙!

task_location.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
                Intent intent = intentBuilder.build(NewTaskActivity.this);
                // Start the Intent by requesting a result, identified by a request code.
                startActivityForResult(intent, 123);


            } catch (GooglePlayServicesRepairableException e) {
                GooglePlayServicesUtil
                        .getErrorDialog(e.getConnectionStatusCode(), NewTaskActivity.this, 0);
            } catch (GooglePlayServicesNotAvailableException e) {
                Toast.makeText(NewTaskActivity.this, "Google Play Services is not available.",
                        Toast.LENGTH_LONG)
                        .show();
            }
        }
    });

这是 list 文件。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    tools:replace="android:icon">

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyAjM9hWUXm8vlABqFbM_fJfQgIFli8HP1E"/>

最佳答案

请检查您应用的 logcat 中是否有“PLACES_API_ACCESS_NOT_CONFIGURED”消息。如果是这种情况,在您的 Google Developer Console 中为此项目启用适用于 Android 的 Google Places API 应该可以解决您的问题。

关于android - Place Picker 启动后自动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30434238/

相关文章:

android - 如何在 Google Autocomplete place API 中使用代码获取所有机场名单

android - 在android中使用google places api时报错 "Status{statusCode=PLACES_API_INVALID_APP, resolution=null}"

android - 新的 Google 地方信息自动填充功能在点击时崩溃

android - 在 ionic 输入中隐藏键盘

android - 如何在 NativeActivity 上禁用屏幕超时

android - 如何在操作完成后重置 EditText?

ios - GMSAutocompleteViewController 想要在搜索点击时获取搜索栏中的文本

android - Google Places Android API 中的 rankby=distance

android - 从地点名称获取对该地点的描述

android - 如何将ANDROID_HOME指向/usr/local/android-sdk?