Android 如何从一个简单的GoogleMaps地址搜索中获取值,并在Flatter中自动完成,然后在TextFormField中显示预测值
在我的代码中,我从TextFormField中搜索带有flatter_google_places的位置,如下所示:Android 如何从一个简单的GoogleMaps地址搜索中获取值,并在Flatter中自动完成,然后在TextFormField中显示预测值,android,google-maps,flutter,dart,google-places,Android,Google Maps,Flutter,Dart,Google Places,在我的代码中,我从TextFormField中搜索带有flatter_google_places的位置,如下所示: TextFormField( decoration: textInputDecoration.copyWith(hintText: 'From') onTap: () async { Prediction p = await PlacesAutocomplete.show( context: context, apiKey: kGoogleApiKey); displa
TextFormField(
decoration: textInputDecoration.copyWith(hintText: 'From')
onTap: () async {
Prediction p = await PlacesAutocomplete.show( context: context, apiKey: kGoogleApiKey);
displayPrediction(p);
},
)
我想在同一个TextFormField中显示结果。这是我的
displayPrediction()
:
未来显示预测(预测p)异步{
如果(p!=null){
位置细节响应细节=
等待地点。getDetailsByPlaceId(p.placeId);
var placeId=p.placeId;
双lat=detail.result.geometry.location.lat;
双液化天然气=详图.result.geometry.location.lng;
var address=await Geocoder.local.findAddressesFromQuery(p.description);
打印(lat);
印刷品(液化天然气);
}}
以下是屏幕截图:为textfieldInput提供一个控制器,例如控制器 ie:控制器:到控制器 然后在displayPrediction方法中,添加 toController.text=地址
Future<Null> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(p.placeId);
var placeId = p.placeId;
double lat = detail.result.geometry.location.lat;
double lng = detail.result.geometry.location.lng;
var address = await Geocoder.local.findAddressesFromQuery(p.description);
print(lat);
print(lng);
}}