google map location picker
map location picker using the official google_maps_flutter.
i made this plugin because google deprecated place picker.
using
for message localization inside the library please add in materialapp
import 'package:google_map_location_picker/generated/i18n.dart' as location_picker;
materialapp(
localizationsdelegates: const [
location_picker.s.delegate,
globalmateriallocalizations.delegate,
globalwidgetslocalizations.delegate,
globalcupertinolocalizations.delegate,
],
supportedlocales: const <locale>[
locale('en', ''),
locale('ar', ''),
],
home: ...
)
import 'package:google_map_location_picker/google_map_location_picker.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
locationresult result = await showlocationpicker(context, apikey);
getting started
get an api key at https://cloud.google.com/maps-platform/.
and don’t forget to enable in https://console.cloud.google.com/google/maps-apis/
- maps sdk for android
- maps sdk for ios
- places api
- geolocation api
- geocoding api
android
specify your api key in the application manifest android/app/src/main/androidmanifest.xml
:
<manifest ...
<application ...
<meta-data android:name="com.google.android.geo.api_key"
android:value="your key here"/>
ios
specify your api key in the application delegate ios/runner/appdelegate.m
:
#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
:
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)
}
}
opt-in to the embedded views preview by adding a boolean property to the app’s info.plist
file with the key io.flutter.embedded_views_preview
and the value yes
; you need also to define nslocationwheninuseusagedescription
<key>nslocationwheninuseusagedescription</key>
<string>this app needs your location to test the location feature of the google maps location picker plugin.</string>
<key>io.flutter.embedded_views_preview</key>
<true/>
note
the following permissions are not required to use google maps android api v2, but are recommended.
android.permission.access_coarse_location
allows the api to use wifi or mobile cell data (or both) to determine the device’s location. the api returns the location with an accuracy approximately equivalent to a city block.
android.permission.access_fine_location
allows the api to determine as precise a location as possible from the available location providers, including the global positioning system (gps) as well as wifi and mobile cell data.
you must also explicitly declare that your app uses the android.hardware.location.network or android.hardware.location.gps hardware features if your app targets android 5.0 (api level 21) or higher and uses the access_coarse_location or access_fine_location permission in order to receive location updates from the network or a gps, respectively.
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
the following permissions are defined in the package manifest, and are automatically merged into your app’s manifest at build time. you don’t need to add them explicitly to your manifest:
android.permission.internet
used by the api to download map tiles from google maps servers.
android.permission.access_network_state
allows the api to check the connection status in order to determine whether data can be downloaded.
credits
the google map from flutter’s google_maps_flutter package
current location and permission from baseflowit’s flutter-geolocator package.
the search bar from degreat’s locationpicker package.
Comments are closed.