【问题标题】:Google's place autocomplete for android keeps giving me "Can't load search results"Google 的 android 位置自动完成功能不断给我“无法加载搜索结果”
【发布时间】:2016-11-19 16:51:18
【问题描述】:

我正在设计一个使用地图并要求用户输入目的地的应用程序。我在 xml 中添加了 PlaceAutoCompleteFragment

分段 android:id="@+id/place_autocomplete_fragment" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_gravity="top" android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />

这就是我的 java 中的内容

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment); autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { // TODO: Get info about the selected place. Log.i(TAG, "Place: " + place.getName()); } @Override public void onError(Status status) { // TODO: Handle the error. Log.i(TAG, "An error occurred: " + status); } });

当我尝试搜索时,它显示:“无法加载搜索结果”。之后我该怎么办?

【问题讨论】:

  • 这对我来说是间歇性发生的。当它发生时很难修复。你找到解决办法了吗?
  • @Josh Smith 你找到解决方案了吗?
  • 你找到解决办法了吗?
  • 谁有这个解决方案?

标签: android google-maps autocomplete google-places-api


【解决方案1】:

autocomplete 小部件是一个具有内置自动完成功能的搜索对话框。

使用PlaceAutocomplete.IntentBuilder 创建一个意图来启动自动完成小部件作为一个意图。设置好可选参数后,调用build(Activity),将intent传递给startActivityForResult(android.content.Intent, int)

int PLACE_AUTOCOMPLETE_REQUEST_CODE = 1;
...
try {
    Intent intent = new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_FULLSCREEN).build(this);
    startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE);
} catch (GooglePlayServicesRepairableException e) {
    // TODO: Handle the error.
} catch (GooglePlayServicesNotAvailableException e) {
    // TODO: Handle the error.
}

若要在用户选择地点时接收通知,您的应用应覆盖 Activity 的 onActivityResult(),检查您为 Intent 传递的请求代码,如下例所示。

@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.getName());
        } 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) {
            // The user canceled the operation.
        }
    }
}

【讨论】:

  • 这不会改变结果。唯一的区别是它会启动一个单独的自动完成活动。但结果是一样的。只是给我“无法加载搜索结果”
猜你喜欢
  • 2017-10-25
  • 1970-01-01
  • 1970-01-01
  • 2018-02-01
  • 1970-01-01
  • 2015-03-15
  • 1970-01-01
  • 2021-07-10
  • 2012-09-27
相关资源
最近更新 更多