Updated 29 April 2023
google_maps_place_picker provides ‘Picking Place’ using Google Maps widget.
You may also explore our Flutter app development page.
Specify your API key in the application manifest android/app/src/main/AndroidManifest.xml
1 2 3 4 5 |
<manifest ... <application ... <meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR KEY HERE"/> |
Note:- Make sure you are using androidX environment for your android project development.
Specify your API key in the application delegate ios/Runner/AppDelegate.m
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include "AppDelegate.h" #include "GeneratedPluginRegistrant.h" #import "GoogleMaps/GoogleMaps.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GMSServices provideAPIKey:@"YOUR KEY HERE"]; [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end |
Or in your swift code, specify your API key in the application delegate ios/Runner/AppDelegate.swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import UIKit import Flutter import GoogleMaps @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) -> Bool { GMSServices.provideAPIKey("YOUR KEY HERE") GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } |
On iOS, you’ll need to add the following entries to your Info.plist file (located under ios/Runner) in order to access the device’s location.
Simply open your Info.plist file and add the following-
1 2 3 4 5 6 |
<key>NSLocationWhenInUseUsageDescription</key> <string>This app needs access to location when open.</string> <key>NSLocationAlwaysUsageDescription</key> <string>This app needs access to location when in the background.</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>This app needs access to location when open and in the background.</string> |
In addition, you need to add the Background Modes
capability to your XCode project (Project > Signing and Capabilties > “+ Capability” button) and select Location Updates
.g> This app needs access to location when open and in the background.
Opt-in to the preview of the embedded view by adding a boolean property to the app’s Info.plist
file with the key io.flutter.embedded_views_preview
and the value YES
.
1 2 |
<key>io.flutter.embedded_views_preview</key> <true/> |
Add the below-mentioned package in your pubspec.yaml file
1 2 3 4 5 |
dependencies: flutter: sdk: flutter google_maps_place_picker: 1.0.1 |
You can use PlacePicker by pushing to a new page using Navigator, OR put as a child of any widget.
When the user picks a place on the map, it will return result to ‘onPlacePicked’ with PickResult type. Alternatively, you can build your own way with ‘selectedPlaceWidgetBuilder’ and fetch result from it (See the instruction below).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Navigator.push( context, MaterialPageRoute( builder: (context) => PlacePicker( apiKey: "@YOUR API KEY HERE" onPlacePicked: (result) { print(result.address); Navigator.of(context).pop(); }, initialPosition: HomePage.kInitialPosition, useCurrentLocation: true, ), ), ); |
By default, the Pin icon is provided with very simple picking animation when moving around.
However, you can also create your own pin widget using ‘pinBuilder’
1 2 3 4 5 6 7 8 9 10 11 12 |
PlacePicker(apiKey: "Your API KEY", ... pinBuilder: (context, state) { if (state == PinState.Idle) { return Icon(Icons.favorite_border); } else { return AnimatedIcon(.....); } }, ... ), ... |
To know more about google_maps_place_picker please check this link
Hopefully, this blog will be helpful to you to understand the Google Maps Place Picker. If you have any queries, please write them in the comment section.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
When i build my custom widget with goolge_maps_place_picker, an error of incompatibility pops up:
Because google_maps_place_picker