我嘗試使用 flutter_google_places: ^0.3.0 自動完成谷歌搜索位置,但輸出只是加載不顯示位置結果。
這是我的代碼,
地圖-example.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 密鑰沒有受到限制,但仍然像這樣發生。
這是我的輸出

感謝您的回復 :)
uj5u.com熱心網友回復:
如果您的帳單在 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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/450902.html
標籤:扑 镖 googleplaces 自动完成
上一篇:主體可能正常完成,導致回傳“null”,但回傳型別可能是不可為空的型別..jsonflutter
下一篇:如果為空,則顫動文本資料?
