android - 如何从一个简单的谷歌地图地址搜索中获取价值,并在 Flutter 中自动完成并在 TextFormField 中显示预测
问题描述
在我的代码中,我正在从 TextFormField 中搜索带有 flutter_google_places 的地方,如下所示:
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);
}}
解决方案
为您的 textfieldInput 提供一个控制器,例如 toController 即:控制器:toController,
然后在您的 displayPrediction 方法中,添加...
toController.text = 地址;
推荐阅读
- asp.net-mvc - EF Core - 存储库、模型或视图模型
- python - 在networkx中快速计算特征向量中心性需要很长时间
- javascript - 为什么这个循环不输出修改后的 CSS?
- javascript - javascript“基本面向对象”,回调和对此感到头疼,希望是一个很好的例子
- epplus - EPPlus - 如何仅复制带有数据的单元格?
- android - 我将如何检索基于 firebase 实时数据库中的第三个节点的节点节点?
- r - 处理基于前 5 个值的制表符分隔文件并使用它打印相邻列值
- ruby-on-rails - 使用 mongodb 获取过去 24 小时内创建的特定订单
- mysql - 如何将关系代数除法转换为sql除法查询?
- php - Windows中的PHP CLI无法访问扩展