简体   繁体   English

使用 flutter_google_places 自动完成搜索不起作用?

[英]Autocomplete search with flutter_google_places doesn't work?

I'm developing my first more complex project, similar to the Uber app idea.我正在开发我的第一个更复杂的项目,类似于 Uber 应用程序的想法。

I follow the instructions in this question autocomplete with flutter我按照这个问题中的说明使用 flutter 自动完成

But when i try to search for addresses, nothing appears但是当我尝试搜索地址时,什么也没有出现

图 1

I'm using GetX for state management我正在使用 GetX 进行 state 管理

Here's my code, in the view:这是我的代码,在视图中:

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),
              )

Method and statements in the controller: controller中的方法和语句:

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

} }

On Google Cloud Platform, 100% of my requests for Api Places result in errors, as shown in the image below在 Google Cloud Platform 上,我对 Api Places 的请求 100% 都会导致错误,如下图所示

谷歌云平台

I saw some forums saying that I was obliged to link the project with a billing account, I did it, but the problem persisted我看到一些论坛说我有义务将项目与计费帐户相关联,我做到了,但问题仍然存在

If someone can help me, thank you in advance如果有人可以帮助我,请提前谢谢

I found the problem.我发现了问题。

My Api key was restricted to "Android Apps" only我的 Api 密钥仅限于“Android 应用”

However, access to an Api Places Google is done through HTTP requests.但是,访问 Api Places Google 是通过 HTTP 请求完成的。

Since my key was restricted, all my requests were resulting in "access denied".由于我的密钥受到限制,我的所有请求都导致“访问被拒绝”。

It was necessary to change the restriction of my API key, as shown in the image below:需要更改我的 API 密钥的限制,如下图所示:

在此处输入图像描述

Remember, changing to "none" is not safe for your application, but in this example it is just a test application, so no problem.请记住,更改为“none”对您的应用程序来说是不安全的,但在此示例中它只是一个测试应用程序,所以没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 flutter_google_places 未显示自动完成搜索结果 - flutter_google_places not showing autocomplete search results Flutter_google_places null 校验算子 - Flutter_google_places null check operator 显然 flutter_google_places 需要代理服务器? - Apparently flutter_google_places requires a proxy server? flutter_google_places 只是加载而不显示结果 - flutter_google_places just loading & not show the result flutter_google_places:pubspec.yaml 文件中的 ^0.2.1 插件错误 - flutter_google_places: ^0.2.1 plugin error in pubspec.yaml file pub 失败:因为 flutter_google_places &gt;=0.2.5 取决于 rxdart ^0.24.0 上 rxdart ^0.23.1, - pub get failed: Because flutter_google_places >=0.2.5 depends on rxdart ^0.24.0 on rxdart ^0.23.1, 使用 GooglePlacesAutocompleteWidget 时强制 flutter_google_places 仅显示城市 - Force flutter_google_places to only display cities when using GooglePlacesAutocompleteWidget Flutter 自动完成谷歌地点表单 - Flutter Autocomplete google places form 当我搜索地址时,Flutter google 自动完成没有显示任何内容,有关如何修复它的任何想法? - Flutter google places autocomplete nothing displayed when I search an address, any idea on how to fix it? 有没有办法在 Flutter 中实现 Google 地方自动完成? - Is there a way to implement Google places autocomplete in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM