这是我的 .xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.root.googlemap.MapsActivity" />
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
这是我的 .java
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
Log.i(TAG,"Place"+ place.getName());
}
@Override
public void onError(Status status) {
Log.i(TAG, "Status" +status);
}
});
我需要根据我在文本视图中的输入加载一些位置。但它没有加载。我认为问题是在同一个文件中使用了两个片段。如何加载位置建议以及如何在 mapfragment 中使用 PlaceAutocompleteFragment。