如何检索用户通过颤振 Google 位置自动完成屏幕选择的位置,以便创建路线?



我只尝试了"p"并通过我的显示路由功能,但我将输出打印到日志中,我得到的只是"p 是'预测'的实例">

child: TextField(onTap: () async{
Prediction p = await PlacesAutocomplete.show(
context: context, apiKey: kGoogleApiKey,
language: "en", components: [new Component(Component.country, "mw")]
print("+++++++$p");
displayRoute(p);

);

预测对象作为参数传递给以下函数,并获取其中所选位置纬度经度地址

void _getLatLng(Prediction prediction) async {    
GoogleMapsPlaces _places = new 
GoogleMapsPlaces(apiKey: API_KEY);    
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(prediction.placeId);    
double latitude = detail.result.geometry.location.lat;
double longitude = detail.result.geometry.location.lng;
String address = prediction.description; 
}

有关更多详细信息,请查看此文章。

最新更新