我正在尝试从displayPrediction()
获取位置值/名称并将其显示在我的textformfield中
这是来自TextFormField的呼叫
TextFormField(
decoration: textInputDecoration.copyWith(hintText: 'From'),
onTap: () async {
Prediction p = await PlacesAutocomplete.show( context: context, apiKey: kGoogleApiKey);
displayPrediction(p);
},
)
我想将地点保存回textformfield。
我的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);
}
}
答案 0 :(得分:0)
只需签出您的Google Places导入依赖项即可。应该如下
import 'package:flutter_google_places/flutter_google_places.dart';
另外,结帐时您已将_places初始化为
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: "YOUR_API_KEY");
答案 1 :(得分:0)
p.description错误。我遇到了同样的问题。 像这样使用它:
List address = [];
address.add(p.description);
print(address);