PlaceAutocompleteFragment显示“无法加载搜索结果”

时间:2018-02-24 07:05:08

标签: android placeautocompletefragment

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
                getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

        autocompleteFragment.setBoundsBias(new LatLngBounds(
                new LatLng(-33.880490, 151.184363),
                new LatLng(-33.858754, 151.229596)));

        AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
                .setTypeFilter(AutocompleteFilter.TYPE_FILTER_ADDRESS)
                .build();

        autocompleteFragment.setFilter(typeFilter);


        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                // TODO: Get info about the selected place.
                Toast.makeText(getApplicationContext(), "Place:" + place.getName(), Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(Status status) {
                // TODO: Handle the error.
                Toast.makeText(getApplicationContext(), "error" + status, Toast.LENGTH_SHORT).show();
            }
        });

搜索无效。当我在搜索文本框中键入地名。它显示“无法加载搜索结果”。我无法解决它。请帮我。感谢。

1 个答案:

答案 0 :(得分:0)

按照以下步骤

在项目gradle中添加依赖项

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile 'com.google.android.gms:play-services-places:10.0.1'

}
apply plugin: 'com.google.gms.google-services'

在主Gradle中添加依赖项

  classpath 'com.google.gms:google-services:3.0.0'

最后您需要在项目中添加 google-services.json 文件