【问题标题】:Autocomplete search with flutter_google_places doesn't work?使用 flutter_google_places 自动完成搜索不起作用?
【发布时间】:2021-04-26 11:19:29
【问题描述】:

我正在开发我的第一个更复杂的项目,类似于 Uber 应用程序的想法。

我按照这个问题autocomplete with flutter中的说明进行操作

但是当我尝试搜索地址时,什么都没有出现

我正在使用 GetX 进行状态管理

这是我的代码, 在视图中:

child: TextField(
                onTap: () async {
                  Prediction p = await PlacesAutocomplete.show(
                      context: Get.context,
                      apiKey: "my_apikey_is_here",
                      language: "pt",
                      components: [Component(Component.country, "br")],
                      mode: Mode.overlay);
                  controller.displayPrediction(p);
                },
                controller: _controllerDestino,
                decoration: InputDecoration(
                    icon: Container(
                      margin: EdgeInsets.only(left: 10),
                      child: Icon(
                        Icons.local_taxi,
                        color: Colors.black,
                      ),
                    ),
                    hintText: "Digite o destino",
                    border: InputBorder.none),
              )

控制器中的方法和语句:

static const kGoogleApiKey = "my_ApiKey_isHere";
GoogleMapsPlaces places = GoogleMapsPlaces(apiKey: kGoogleApiKey);



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);
  update();
}

}

在 Google Cloud Platform 上,我对 Api Places 的请求 100% 都会导致错误,如下图所示

我看到一些论坛说我有义务将项目与结算帐户相关联,我做到了,但问题仍然存在

如果有人可以帮助我,请提前感谢您

【问题讨论】:

    标签: flutter google-places-api google-maps-flutter flutter-getx


    【解决方案1】:

    我发现了问题。

    我的 Api 密钥仅限于“Android 应用”

    但是,对 Api Places Google 的访问是通过 HTTP 请求完成的。

    由于我的密钥受到限制,我的所有请求都导致“访问被拒绝”。

    需要更改我的API密钥的限制,如下图所示:

    请记住,更改为“none”对您的应用程序不安全,但在此示例中它只是一个测试应用程序,所以没问题。

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      • 2021-08-29
      • 1970-01-01
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      相关资源
      最近更新 更多