showLocationPicker function
Future<LocationResult?>
showLocationPicker(
- BuildContext context,
- String apiKey, {
- LatLng initialCenter = const LatLng(45.521563, -122.677433),
- double initialZoom = 16,
- bool requiredGPS = false,
- List<
String> countries = const ["IN"], - bool myLocationButtonEnabled = false,
- bool layersButtonEnabled = false,
- bool automaticallyAnimateToCurrentLocation = true,
- String? mapStylePath,
- Color appBarColor = Colors.transparent,
- BoxDecoration? searchBarBoxDecoration,
- String? hintText,
- Widget resultCardConfirmIcon = const Icon(Icons.arrow_forward),
- Alignment resultCardAlignment = Alignment.bottomCenter,
- EdgeInsets resultCardPadding = const EdgeInsets.all(16.0),
- Decoration? resultCardDecoration,
- String language = 'en',
- LocationAccuracy desiredAccuracy = LocationAccuracy.best,
Returns a LatLng
object of the location that was picked.
The apiKey
argument API key generated from Google Cloud Console.
You can get an API key here
initialCenter
The geographical location that the camera is pointing
until the current user location is know if you want to change this
set automaticallyAnimateToCurrentLocation
to false.
Implementation
Future<LocationResult?> showLocationPicker(
BuildContext context,
String apiKey, {
LatLng initialCenter = const LatLng(45.521563, -122.677433),
double initialZoom = 16,
bool requiredGPS = false,
List<String> countries = const ["IN"],
bool myLocationButtonEnabled = false,
bool layersButtonEnabled = false,
bool automaticallyAnimateToCurrentLocation = true,
String? mapStylePath,
Color appBarColor = Colors.transparent,
BoxDecoration? searchBarBoxDecoration,
String? hintText,
Widget resultCardConfirmIcon = const Icon(Icons.arrow_forward),
Alignment resultCardAlignment = Alignment.bottomCenter,
EdgeInsets resultCardPadding = const EdgeInsets.all(16.0),
Decoration? resultCardDecoration,
String language = 'en',
LocationAccuracy desiredAccuracy = LocationAccuracy.best,
}) async {
final results = await Navigator.of(context).push(
MaterialPageRoute<dynamic>(
builder: (BuildContext context) {
// print('[LocationPicker] [countries] ${countries.join(', ')}');
return LocationPicker(
apiKey,
initialCenter: initialCenter,
initialZoom: initialZoom,
requiredGPS: requiredGPS,
myLocationButtonEnabled: myLocationButtonEnabled,
layersButtonEnabled: layersButtonEnabled,
automaticallyAnimateToCurrentLocation:
automaticallyAnimateToCurrentLocation,
mapStylePath: mapStylePath,
appBarColor: appBarColor,
hintText: hintText,
searchBarBoxDecoration: searchBarBoxDecoration,
resultCardConfirmIcon: resultCardConfirmIcon,
resultCardAlignment: resultCardAlignment,
resultCardPadding: resultCardPadding,
resultCardDecoration: resultCardDecoration,
countries: countries,
language: language,
desiredAccuracy: desiredAccuracy,
);
},
),
);
if (results != null && results.containsKey('location')) {
return results['location'];
} else {
return null;
}
}