2

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

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
sainu
  • 2,686
  • 3
  • 22
  • 41

4 Answers4

5

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

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

Hayi Nukman
  • 1,191
  • 12
  • 29
  • let me check with the example – sainu Aug 14 '19 at 09:26
  • your code snippet is similar to this: https://github.com/fluttercommunity/flutter_google_places/blob/master/example/lib/main.dart ,, so I thought it's the same problem.... – Hayi Nukman Aug 14 '19 at 09:30
  • 1
    As @HayiNukman mentioned, you need to import `google_maps_webservice packages` to be able to use `GoogleMapPlaces` class, as it extends from `GoogleWebServices`. The package that you imported `flutter_google_places` is used to leverage the autocomplete field and the places. – Darshan Aug 14 '19 at 09:42
3

you can find another package for google place google_place

var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.autocomplete.get("1600 Amphitheatre");
M.B
  • 609
  • 4
  • 10
  • As a general rule you should describe why this one is better or probably even why you think this will solve the problem the poster has, as part of that it would probably also be beneficial to describe why the original package has the particular problem, otherwise your suggestion seems like flail around trying packages until something works. which is probably not the strategy you actually want them to pursue. – user254694 Apr 25 '20 at 11:53
0

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

Berkant Ay
  • 60
  • 2
  • 8
0

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));
                          })
Saad
  • 539
  • 2
  • 19
Ammar bam
  • 1
  • 2