我想使用PlacesAutocomplete获取地点并将其存储在我的TextFormField中。我正在从displayPrediction()
]呼叫TextFormFeild()
TextFormField( decoration: textInputDecoration.copyWith(hintText: 'From'), onTap: () async { Prediction p = await PlacesAutocomplete.show( context: context, apiKey: kGoogleApiKey, mode: Mode.overlay, //language: "en", //components: [Component (Component.country, "en")], ); displayPrediction(p); }, ),
这里是
displayPrediction()
:
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); print(address); } }
变量kGoogleApiKey和_places
const kGoogleApiKey = "My_API_Key";
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);
并且选择位置后出现此错误-_TypeError (type 'List<dynamic>' is not a subtype of type 'PlaceDetails')
我想使用PlacesAutocomplete获取地点并将其存储在我的TextFormField中。我从TextFormFeild()TextFormField(装饰:textInputDecoration ....