Search code examples
fluttergoogle-mapsgoogle-place-picker

How to Use autocompleteComponents in PlacePicker Package Flutter


I am Using the PlacePicker Package for Flutter , the package has a parameter called

autocompleteComponents : A grouping of places to which you would like to restrict your results. Currently, you can use components to filter by up to 5 countries.

but I can't find anywhere how to use this parameter i can't initiate a list of components


Solution

  • Found the Answer

    import 'package:google_maps_webservice/places.dart' as google_maps_api;
    ...
    PlacePicker(
    apiKey: APIKeys.apiKey,   // Put YOUR OWN KEY here.
    autocompleteComponents: [
        google_maps_api.Component("country", "fr") //restrict search results to France
    ],
    onPlacePicked: (result) { 
        print(result.address); 
        Navigator.of(context).pop();
    },
    initialPosition: HomePage.kInitialPosition,
        useCurrentLocation: true,
    ),
    

    source an example of how to use autocompleteComponents #111