PlaceAutocomplete崩溃,没有任何错误在logcat中

时间:2018-02-26 13:06:54

标签: android google-maps-android-api-2 android-search

我正在尝试在片段中实现PlaceAutoCompleteFragment。我最终得到了这个(基于this question的接受答案):

public class SecondFragment extends Fragment
        implements OnMapReadyCallback {

      PlaceAutocompleteFragment placeAutoComplete;
      .....

      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View view = inflater.inflate(R.layout.fragment_second, null, false);


        // Create Map
        if (savedInstanceState != null) {
            mLastKnownLocation = savedInstanceState.getParcelable(KEY_LOCATION);
            mCameraPosition = savedInstanceState.getParcelable(KEY_CAMERA_POSITION);
            latlang.Lat = mLastKnownLocation.getLatitude();
            latlang.Lang = mLastKnownLocation.getLongitude();
        }

        // Construct a FusedLocationProviderClient.
        mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(getContext());
        getLocationPermission();
        getDeviceLocation();

        placeAutoComplete = (PlaceAutocompleteFragment) getActivity().getFragmentManager().findFragmentById(R.id.place_autocomplete);
        placeAutoComplete.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {

                    Log.d("Maps", "Place selected: " + place.getName());
                }

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


        SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        //Search Place


        return view;
      }

并且相应的布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SecondFragment"
    android:orientation="vertical"
    android:weightSum="1">

    <fragment
        android:id="@+id/place_autocomplete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
        />

    <fragment
        android:id="@+id/map"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


</LinearLayout>

所以,我得到一个searchbar,点击打开,键盘闪烁一秒然后崩溃,然后开始打字,然后返回&#34;点击&#34;图。

这里出了什么问题?

0 个答案:

没有答案