【发布时间】:2019-03-02 23:55:07
【问题描述】:
我正在尝试通过 intentBuilder 创建一个意图来实现 google Places API(Places Autocomplete)。我的应用通过单击按钮成功获得了意图,但无法搜索地点。
在覆盖 onActivityResult 时,它得到 resultCode = 2 而不是 RESULT_SUCCESS、RESULT_ERROR 或 RESULT_CANCELLED 并返回 MainActivity。
我参考了https://developers.google.com/places/android-api/autocomplete 并添加了依赖项
compile 'com.google.android.gms:play-services-places:9.2.0'
这是我的代码
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(this, data);
Log.i(TAG, "Place: " + place.getAddress());
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
// TODO: Handle the error.
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
Log.i("message", "the user cancelled the operation" ); }
}
}
我需要一些帮助,请帮助。
【问题讨论】:
标签: android google-places-api onactivityresult