【发布时间】:2021-11-24 15:02:19
【问题描述】:
我想使用 Place Autocomplete 所以我阅读了谷歌文档 我使用了“嵌入 AutocompleteSupportFragment”选项 但我输入的完全一样,是谷歌写的,但是有这样的错误
- 类“派生自 PlaceSelectionListener 的匿名类”必须声明为抽象或在“PlaceSelectionListener”中实现抽象方法“onPlaceSelected(Place)”
- 方法不会覆盖其超类中的方法
我确实覆盖了方法“onPlaceSelected”,但是当我输入代码时,代码变为灰色并在下面的 PlaceSelectionListener 处创建红线..
我不知道为什么,请帮忙...
代码在这里
public class FinalTest extends FragmentActivity {
private static int AUTOCOMPLETE_REQUEST_CODE = 1;
private static final String TAG = "FinalTest";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_test);
Places.initialize(getApplicationContext(), "my_api_key");
PlacesClient placesClient = Places.createClient(this);
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
// Specify the types of place data to return.
autocompleteFragment.setTypeFilter(TypeFilter.ADDRESS);
autocompleteFragment.setLocationBias(RectangularBounds.newInstance(
new LatLng(-33.880490, 151.184363),
new LatLng(-33.858754, 151.229596)));
autocompleteFragment.setCountries("IN");
autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID,Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
}
}
【问题讨论】:
标签: android google-maps autocomplete