sainu
sainu

Reputation: 2701

Google Places API in Flutter

I am working on google places API with Flutter. I am working by referring the example. But I got errors for google places API classes as

Eg:

Undefined class 'GoogleMapsPlaces'. Try changing the name to the name of an existing class, or creating a class with the name

I imported the flutter_google_places in my dart file as:

import 'package:flutter_google_places/flutter_google_places.dart'; But still I got the error for all classes.

Using flutter_google_places version 0.2.3.

enter image description here

Upvotes: 2

Views: 12960

Answers (4)

Ammar bam
Ammar bam

Reputation: 1

Try to use google_places_flutter, and include this code in 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));
                          })

Upvotes: 0

Berkant Ay
Berkant Ay

Reputation: 72

You need to import import 'package:google_maps_webservice/places.dart'; in your main.dart.

Upvotes: 0

M.B
M.B

Reputation: 619

you can find another package for google place google_place

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

Upvotes: 3

Hayi Nukman
Hayi Nukman

Reputation: 1201

GoogleMapPlaces is available on different library, not in flutter_google_places...

it's available on https://pub.dev/packages/google_maps_webservice

Upvotes: 6

Related Questions