Comment on page
The PlacePicker widget is used to get information about the places like establishments (buildings, parks, museums, etc) and geographic locations (roads, lakes, mountains, etc). This information includes name, address, city, state, country, zip code, and LatLong details.
A pretty common use case of using the PlacePicker widget is in a cab booking app. For example, you could use the PlacePicker widget to get the exact location of a place (LatLong) with the full address to display on a page or a Google Map.
The PlacePicker widget looks like a button. When you tap on it, it allows you to search for a place. As you start typing the place name, it shows a list of matching places. On selecting the place, the place name appears on a button. The other information about the place is accessible using the placePickerValue variable (from Widget State).
Let's build a simple example that shows selected place details in a Text widget. Here is how it looks:
Adding PlacePicker and showing the place information comprises of following steps
If you have a billing account created while setting up the Firebase, you can verify if your existing account support Google Maps Platform Billing here. Basically, if your billing account supports USD billing, skip this step.
Failing to enable the Google Maps Platform Billing will not show any place in an autocomplete list.
Enabling Places API allows you to access the Google Maps servers and returns the information about the place.
To enable Places API:
- 2.Click on the APIs & Services -> Library menu on the left.
- 3.Search and select the Places API card.
- 4.Click Enable.
Enable Places API
You must add the API keys to your FlutterFlow project that will allow your app to communicate with the Google server.
You can skip this step if you have already added the keys while setting up the Google Map.
To add the API keys:
- 2.Click the APIs & Services -> Credentials menu on the left.
- 3.Find the key Android key (auto-created by Firebase), click on SHOW KEY and then copy the key (click onicon)
- 4.Now, go to the FlutterFlow project, and navigate to Settings and Integrations > Integrations > Google Maps.
- 5.Find the Android API Key input box and paste the key.
- 6.Similarly, copy the iOS key (auto-created by Firebase) and Browser key (auto-created by Firebase) from the Google developer console and paste it into the iOS API Key and Web API Key input boxes respectively.
Add keys to FlutterFlow
To add the PlacePicker widget to your project:
- 1.Drag the PlacePicker widget from the Form Elements tab (in the Widget Panel) or add it directly from the widget tree.
- 2.Below the PlacePicker widget add some Text widgets to show the information about the place.
Adding PlacePicker widget
After adding the PlacePicker widget, you can display all information about the place such as name, address, and state by accessing the placePickerValue from the Widget State.
To retrieve the place information:
- 1.Select the Text widget from the widget tree or from the canvas area.
- 2.Move to the properties panel, and click on the Set from Variable.
- 3.Set the Source to Widget State.
- 4.Set the Available Options to placePickerValue.
- 5.Select the Place Fields to the field that you would like to display.
- 6.Set the Default Value if you wish to. This will be displayed if the value from the field is empty.
Retrieve place information
Sometimes you might want to show the selected place from the PlacePicker widget on to the Map. For example, setting the pickup and drop location on the map. You can achieve this by adding the Move Map Center action and providing the LatLong values retrieved from the PlacePicker widget.
Let's build an example showing the selected place on Google Map. Here is what it looks like:
Showing selected place on Google Map
The steps to build the example are as follows:
To build the UI:
- 1.First, remove the Column widget and replace it with the Stack widget from the Form Elements tab (in the Widget Panel) or add it directly from the widget tree.
- 2.Inside the Stack, add the Google Map widget to show the place location.
- 3.Now, add the PlacePicker widget and rearrange its position.
- 4.Add the Button widget to add an action that will bring the selected place to the center.
You can add an action to move the map and show the location in the center by following the instructions on the below page.