google_places_sdk 1.2.1

SDKflutter
Platformandroidios

A flutter plugin to use google places SDK. This plugin supports Auto complete, place details and google photos.

google_places

A flutter plugin for Google Places SDK with Android & iOS support.

AndroidiOS
SupportSDK 16+iOS 12+

Usage

To use this plugin please add google_places to your pubspec.yaml file.

Initialize Plugin

First, you need to initialize the plugin.

await GooglePlaces().initialize(
  "Your maps key here",
  locale: const Locale('ar'),
);

There you go, you can now use the plugin.

Change Locale

You can change your locale.

await GooglePlaces().updateLocale(const Locale('en'));

Note that setting locale is only supported on Android. As iOS will use the device language.

Get autocomplete results

After initializing the plugin, you can fetch auto complete search results from a query.

final List<AutocompletePrediction> results = await GooglePlaces().getAutoCompletePredictions('Great Pyramid of Giza');

Parameters:

ParameterTypeCondition
queryStringRequired
countryCodesList<String>Optional
locationBiasRectangularBoundsOptional
locationRestrictionRectangularBoundsOptional
placeTypesList<PlaceType>Optional
cancellationTokenCancellationTokenOptional

Get Place Details

You can get place details by passing the id to plugin.

final PlaceDetails placeDetails = await GooglePlaces.fetchPlaceDetails('Your Place Id');

Parameters:

ParameterTypeCondition
placeIdStringRequired
placeFieldsList<PlaceField>Optional
cancellationTokenCancellationTokenOptional

Get Place Photo

After fetching place details, you might need to fetch the place photo. Here's an example:

final Uint8List? photo = await GooglePlaces().fetchPlacePhoto(widget.metadata);

Cancelling Requests

The plugin supports the cancellation of a requst to the Google API.

final token = CancellationToken();
final details = await GooglePlaces.fetchPlaceDetails('Your Place Id', cancellationToken: token);
await token.cancel();

Note that issuing a cancellation token does NOT guarantee that a particular request will be cancelled, and you may still be charged for the request even if no response is returned.

Note that this feature is supported only on Android.

Feature Support

FeatureAndroidiOS
Soft Localization
Device Localizations
Place Autocomplete
Place Details
Current Place
Place Photo
Request Cancellation

Platform Support

PlatformVersion
AndroidSDK 16+
iOS11+
WebNot yet supported
LinuxNot yet supported
MacOSNot yet supported
WindowsNot yet supported