目前,我正在使用PlaceAPI库获取位置ID。
objPlacesAPI = new PlaceAPI.Builder()
.apiKey("KEY")
.build(this);
autoCompleteEditText = (AutoCompleteTextView) findViewById(R.id.autoCompleteEditText);
autoCompleteEditText.setAdapter(new PlacesAutoCompleteAdapter(this, objPlacesAPI));
autoCompleteEditText.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Place place = (Place) parent.getItemAtPosition(position);
autoCompleteEditText.setText(place.getDescription());
objPlacesAPI.fetchPlaceDetails(place.getId(), new OnPlacesDetailsListener() {
@Override
public void onError(@NotNull String errorMessage) {
String a = "";
}
@Override
public void onPlaceDetailsFetched(@NotNull PlaceDetails placeDetails) {
String a = "";
}
});
}
});
在上面的代码中,我成功获得了位置,但是我调用了fetchPlaceDetails,但出现错误“无法处理JSON结果”