androidplaceautocompletefragment

PlaceAutocompleteFragment show "Can't load searching result"


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();
            }
        });

The searching is not working. When I type place name in the searching text box. It show "Can't load the searching result". I cann't solve it. Please help me. Thanks.


Solution

  • Follow this steps

    Add dependencies in project 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'
    

    Add dependencies in main Gradle

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

    At Last you need to add google-services.json file in you project