1

I am currently working on an app that uses google places autocomplete to find addresses around the world. I have implemented it in the following way:

Position currentPosition;
var placeId, address;
double lat, lng;

 getCurrentLocation(){
    final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
    geolocator
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
      .then((Position position){
        setState(() {
          currentPosition = position;
        });
      }).catchError((e){
        print(e);
      });
  }

Future<Null> displayPrediction(Prediction p) async {
    if (p != null) {
      PlacesDetailsResponse detail = await _places.getDetailsByPlaceId(p.placeId);
      placeId = p.placeId;
      lat = detail.result.geometry.location.lat;
      lng = detail.result.geometry.location.lng;
      address = await Geocoder.local.findAddressesFromQuery(p.description);
    }
  }

onPressed: () async {
  print(currentPosition.latitude);
  print(currentPosition.longitude);
  Prediction prediction = await PlacesAutocomplete.show(
    context: context, 
    apiKey: googleApiKey,
    location: Location(currentPosition.latitude, currentPosition.longitude),
    radius: 100000000,
    mode: Mode.overlay,
    language: "en",
  );

However, whenever I type something into the search bar, I do not receive any autocompleted results and I am not sure why (image attached). If it makes any difference, I am using the iOS simulator. I haven't yet tested on Android. Any help would be much appreciated.

enter image description here

Community
  • 1
  • 1
flutterbug98
  • 111
  • 2
  • 11
  • Hope this helps : https://stackoverflow.com/questions/55870508/how-to-create-a-simple-google-maps-address-search-with-autocomplete-in-flutter-a/55877236#55877236 – Darshan Jan 13 '20 at 04:52
  • That was in fact the code I used for inspiration. However, it doesn't seem to work for me. I have done some research and found that people said it wasn't working because they haven't enabled billing. Could that be a problem with mine? – flutterbug98 Jan 13 '20 at 04:55
  • Could it be that access to api is being denied. Please check if the api is enabled. See this for reference: https://github.com/fluttercommunity/flutter_google_places/issues/51 – Darshan Jan 13 '20 at 05:02
  • I believe my api is enabled. But I have not linked a billing account – flutterbug98 Jan 13 '20 at 05:41
  • Linking a billing account is mandatory. Please follow Google's get started guide to set up your project and billing account correctly at https://developers.google.com/maps/gmp-get-started – evan Jan 17 '20 at 14:08

0 Answers0