我正在开发我的项目来创建一个带有导航抽屉的活动(扩展AppCompatActivity),用于在多个Fragment之间切换,其中一个是MapFragment(使用MapView实现扩展Fragment).我想在MapFragment类中调用Google提供的AutoComplete Widget.
这是我在MapFragment类中的代码
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
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.
String placeDetailsStr = place.getName() + "\n"
+ place.getId() + "\n"
+ place.getLatLng().toString() + "\n"
+ place.getAddress() + "\n"
+ place.getAttributions();
Log.i("OnPlaceSelected", placeDetailsStr);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 15));
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i("OnPlaceSelected", "An error occurred: " + status);
}
});
Run Code Online (Sandbox Code Playgroud)
语法错误是在 …