首页 > 解决方案 > Google Places AutoComplete 搜索时不显示地址

问题描述

我目前正在开发一个应用程序,该应用程序使用 google 地方自动完成功能来查找世界各地的地址。我已经通过以下方式实现了它:

Position currentPosition;
var placeId, address;
double lat, lng;

 getCurrentLocation(){
    final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
    geolocator
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
      .then((Position position){
        setState(() {
          currentPosition = position;
        });
      }).catchError((e){
        print(e);
      });
  }

Future<Null> displayPrediction(Prediction p) async {
    if (p != null) {
      PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
      placeId = p.placeId;
      lat = detail.result.geometry.location.lat;
      lng = detail.result.geometry.location.lng;
      address = await Geocoder.local.findAddressesFromQuery(p.description);
    }
  }

onPressed: () async {
  print(currentPosition.latitude);
  print(currentPosition.longitude);
  Prediction prediction = await PlacesAutocomplete.show(
    context: context, 
    apiKey: googleApiKey,
    location: Location(currentPosition.latitude, currentPosition.longitude),
    radius: 100000000,
    mode: Mode.overlay,
    language: "en",
  );

但是,每当我在搜索栏中输入内容时,我都不会收到任何自动完成的结果,而且我不知道为什么(附图)。如果有什么不同,我使用的是 iOS 模拟器。我还没有在安卓上测试过。任何帮助将非常感激。

在此处输入图像描述

标签: flutterdartgoogle-places-api

解决方案


推荐阅读