Flutter中的Google Places API

icomxhvb  于 2023-06-24  发布在  Flutter
关注(0)|答案(4)|浏览(181)

我正在使用Flutter开发Google Places API。我正在使用example。但我得到了错误的谷歌地方API类为
例如:
Undefined class 'targeted'。请尝试将名称更改为现有类的名称,或创建一个具有名称的类
我在dart文件中导入flutter_google_places为:
import 'package:flutter_google_places/flutter_google_places.dart';但是我仍然得到了所有类的错误。
使用flutter_google_places版本0.2.3

8ehkhllq

8ehkhllq1#

GoogleMapPlaces可在不同的库中使用,而不是flutter_google_places...
它在https://pub.dev/packages/google_maps_webservice上可用

kadbb459

kadbb4592#

你可以找到另一个包为谷歌地方google_place

var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.autocomplete.get("1600 Amphitheatre");
brqmpdu1

brqmpdu13#

您需要在main.dart中导入import 'package:google_maps_webservice/places.dart';

n3schb8v

n3schb8v4#

Try to use google_places_flutter, and nclude ths code to your screen:




GooglePlaceAutoCompleteTextField(
                          textEditingController: controller,
                          googleAPIKey:
                              "YOUR-API-KEY
",
                          inputDecoration:
                              InputDecoration(hintText: "Enter your address"),
                          debounceTime: 800, // default 600 ms,
                          countries: ["my"], // optional by default null is set
                          isLatLngRequired:
                              true, // if you required coordinates from place detail
                          getPlaceDetailWithLatLng:
                              (Prediction prediction) async {
                            // this method will return latlng with place detail
                            print("placeDetails" + prediction.lng.toString());
                            print("placeDetails" + prediction.lat.toString());
                            
                          }, // this callback is called when isLatLngRequired is true
                          itmClick: (Prediction prediction) {
                            controller.text = prediction.description.toString();
                            controller.selection = TextSelection.fromPosition(
                                TextPosition(
                                    offset: prediction.description!.length));
                          })

相关问题