Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从一个简单的GoogleMaps地址搜索中获取值,并在Flatter中自动完成,然后在TextFormField中显示预测值_Android_Google Maps_Flutter_Dart_Google Places - Fatal编程技术网

Android 如何从一个简单的GoogleMaps地址搜索中获取值,并在Flatter中自动完成,然后在TextFormField中显示预测值

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中搜索带有flatter_google_places的位置,如下所示:

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);
}}