地点自动完成功能始终返回无法加载搜索结果

时间:2019-07-27 17:26:07

标签: java android api

我想在应用程序中添加在地图上选择位置的可能性,因此我对Google Place Api进行了限定,我在xml文件中创建了一个片段,例如thi

<fragment
        android:id="@+id/autocomplete_fragment"
        android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

这是我的代码:

public class StrutturaEdit extends AppCompatActivity {
    PlacesClient placesClient;
    List<Place.Field> placeFields = Arrays.asList(Place.Field.ID,
            Place.Field.NAME,
            Place.Field.ADDRESS);

    AutocompleteSupportFragment places_fragment;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        ........  

        Places.initialize(this, getString(R.string.google_maps_key));
        placesClient = Places.createClient(this);

        setupPlaceAutocomplete();
    }

    private void setupPlaceAutocomplete() {
        places_fragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
        places_fragment.setPlaceFields(placeFields);

        places_fragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                Log.i("TAG", "Place: " + place.getName() + ", " + place.getId());
            }

            @Override
            public void onError(Status status) {
                Log.i("TAG", "An error occurred: " + status);
            }
        });

所以我可以进行搜索,但是我没有结果。我总是得到“无法加载结果”:

search results

我该怎么办?

0 个答案:

没有答案