如何使用点击位置的纬度和经度获取 Flutter 中位置的自动完成位置?

How to get autocomplete location of places in Flutter with Latitude and Longitude of tapped place?

在我的应用程序中,我希望用户输入一个地点(并且 flutter_google_places 必须显示地点建议)。然后我想得到他点击的那个地方的经纬度

问题:我看过这个答案:

这与我的问题类似,但对我不起作用!

我的代码:

Completer<GoogleMapController> _controller = Completer();
final api_key=API_KEY;
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: API_KEY);
LocationData user_location=LoginPage.LD;








@override
Widget build(BuildContext context) {

   CameraPosition cuurent_location_of_user = CameraPosition(

   target: LatLng(user_location.latitude,user_location.longitude),
   zoom: 16,
 );


return Scaffold(
  body: Stack(
    children: <Widget>[
      Container(
      child:GoogleMap(
        mapType: MapType.hybrid,
        initialCameraPosition: cuurent_location_of_user,
        onMapCreated: (GoogleMapController controller) {
          _controller.complete(controller);
        },
      )
      ),
      Container(
          alignment: Alignment.center,
          child: RaisedButton(
            onPressed: () async {

               Prediction p =  await PlacesAutocomplete.show(
                  context: context, apiKey: api_key);
              displayPrediction(p);

            },


          )
      ),
    ],
  ),

);
}
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(p.toString()); 它 returns 空 我无法在我的代码中找到问题 我还在 Google 云服务中启用了 API 的位置,并且我还使用了最近的 API_KEY

谢谢

我想我得到了答案。 我忘记在我的 google 云平台中创建结算帐户。