在折旧期间,我有什么办法可以实现Google地点选择器?

时间:2019-05-16 02:53:38

标签: java android android-intent google-places-api startactivityforresult

因此,我正在尝试构建一个Android应用,其中必须有Place Picker API。首先,我在开发人员控制台中创建了一个项目,对该项目启用了计费功能,还创建了一个API密钥。

然后,我将该API密钥插入清单的meta-data部分(在application标记内)。

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_place_api" />
</application>

在那之后,我还将新的places SDK包含在我的build.gradle(app)

dependencies {
    implementation 'com.google.android.libraries.places:places-compat:1.1.0'
}

并创建了一个活动来实现此地点选择器API:

public class maps extends AppCompatActivity {
    int PLACE_PICKER_REQUEST = 999;
    public static Place place;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        try {
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            startActivityForResult(builder.build(maps.this), PLACE_PICKER_REQUEST);
        } catch (GooglePlayServicesRepairableException e) {
            e.printStackTrace();
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PLACE_PICKER_REQUEST) {
            if (resultCode == RESULT_OK) {
                 place =  PlacePicker.getPlace(data, this);
                String toastMsg = String.format("Place: %s", place.getAddress());
                Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
            }
        }
    }
}

完成所有这些步骤之后,当我尝试从MainActivity.class的意图调用此活动时,这就是我得到的:

2019-05-12 08:07:57.106 2818-3899/? E/Volley: [171] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/placePicker?key=AIzaSyCz-bC6nazJur-gHEgVoZMujFDyVvsXXXX
2019-05-12 08:07:57.110 2818-20254/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.

这很奇怪,因为我已经为Android启用了Places API。我现在该怎么办?

0 个答案:

没有答案