我只尝试了"p"并通过我的显示路由功能,但我将输出打印到日志中,我得到的只是"p 是'预测'的实例">
child: TextField(onTap: () async{
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: kGoogleApiKey,
language: "en", components: [new Component(Component.country, "mw")]
print("+++++++$p");
displayRoute(p);
);
将预测对象作为参数传递给以下函数,并获取其中所选位置的纬度、经度和地址。
void _getLatLng(Prediction prediction) async {
GoogleMapsPlaces _places = new
GoogleMapsPlaces(apiKey: API_KEY);
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(prediction.placeId);
double latitude = detail.result.geometry.location.lat;
double longitude = detail.result.geometry.location.lng;
String address = prediction.description;
}
有关更多详细信息,请查看此文章。