簡體   English   中英

flutter_google_places 只是加載而不顯示結果

[英]flutter_google_places just loading & not show the result

我嘗試使用 flutter_google_places: ^0.3.0 來自動完成谷歌搜索位置,但 output 只是加載而不顯示位置結果。

這是我的代碼,

地圖示例.dart

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart' as Loc;
import 'package:geocoding/geocoding.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_maps_webservice/places.dart';

const kGoogleApiKey = "YourAPIKEY";
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);

class MapScreen extends StatefulWidget {
  static const String routeName = '/maps';

  const MapScreen({Key? key}) : super(key: key);

  @override
  _MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          RaisedButton(
            onPressed: () async {
              Prediction? p = await PlacesAutocomplete.show(
                context: context,
                apiKey: kGoogleApiKey,
                mode: Mode.overlay,
                radius: 10000000,
                types: [],
                strictbounds: false,
                decoration: InputDecoration(
                  hintText: 'Search Location',
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(20),
                    borderSide: BorderSide(
                      color: Colors.white,
                    ),
                  ),
                ),
              );
            },
          )
        ],
      ),
    );
  }
}

我已經檢查過我的 api 密鑰沒有受到限制,但仍然這樣發生。

這是我的 output

在此處輸入圖像描述

感謝您的回復:)

如果您的賬單在 Google APIS 上激活,請嘗試添加組件

   Prediction? p =
                                        await PlacesAutocomplete.show(
                                            context: context,
                                            radius: 10000000,
                                            types: [],
                                            logo: const SizedBox.shrink(),
                                            strictbounds: false,
                                            mode: Mode.overlay,
                                            language: "fr",
                                            components: [ //add this 
                                              Component(
                                                  Component.country, "fr"),
                                              Component(
                                                  Component.country, "in"),
                                              Component(Component.country, "UK")
                                            ],
                                            apiKey: kGoogleApiKey);

我遇到了同樣的問題,正如@Ashutosh singh 的評論中所暗示的那樣,這是我的賬單賬戶被關閉了。 我不確定它為什么關閉,但我只是瀏覽到 Google API 控制台,找到該項目,選擇結算帳戶並“重新打開”搜索,然后立即返回結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM