location_picker_flutter 1.1.0 location_picker_flutter: ^1.1.0 copied to clipboard
A location picker package that allows the use to pick a location and get the address via GPS, Map or Autocomplete Google Apis.
LocationPickerFlutter #
LocationPickerFlutter
is a customizable Flutter widget that allows users to pick a location through Google Maps. It integrates Google Maps, Places API, and Geolocation services to offer a seamless location selection experience. Users can either select a location on the map, use their current location, or search for a location through Google Places Autocomplete.
Features #
- Google Maps integration for interactive location picking.
- Search functionality using Google Places Autocomplete.
- Option to display or hide map types (Satellite, Terrain, etc.).
- Supports zoom and rotate gestures.
- Current location detection and navigation.
- Customizable location details display.
- Session token support for Google Places API requests.
Installation #
To use this package, add it to your pubspec.yaml
file:
dependencies:
location_picker_flutter: ^1.0.0
Getting Started #
- Add your Google Maps API Key to the widget's constructor.
- Customize the
InitialSettings
to specify the starting position and other settings. - Use the
LocationPickerFlutter
widget in your app wherever you need location selection.
Adding Google Maps API Key #
To use Google Maps and Places APIs in your app, you need to add your API key to both Android and iOS.
Android
-
Open the
AndroidManifest.xml
file inandroid/app/src/main/
. -
Add the following inside the
<application>
tag:<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_GOOGLE_MAPS_API_KEY" />
Replace YOUR_GOOGLE_MAPS_API_KEY
with your actual Google Maps API key.
iOS
-
Open
AppDelegate.swift
file inios/Runner/
. -
Import Google Maps at the top of the file:
import GoogleMaps
-
Inside
@UIApplicationMain
inAppDelegate
, add the following indidFinishLaunchingWithOptions
:GMSServices.provideAPIKey("YOUR_GOOGLE_MAPS_API_KEY")
Again, replace YOUR_GOOGLE_MAPS_API_KEY
with your actual key.
Example Usage #
import 'package:flutter/material.dart';
import 'package:location_picker_flutter/location_picker_flutter.dart';
import 'package:location_picker_flutter/models/initial_settings.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Location Picker',
home: Scaffold(
appBar: AppBar(title: Text('Location Picker Example')),
body: LocationPickerFlutter(
googleMapsApiKey: 'YOUR_GOOGLE_MAPS_API_KEY', // Your API key here
intialLocation: InitialSettings(
latitude: 37.7749,
longitude: -122.4194,
zoomLevel: 10,
),
showMapTypes: true,
showZoomControls: true,
canZoom: true,
canRotate: true,
searchHint: "Search for locations...",
sessionToken: "", // Optionally provide a session token
),
),
);
}
}
Constructor Parameters #
googleMapsApiKey
: String - Your Google Maps API key.intialLocation
: InitialSettings - Initial settings for the map, including the starting location and zoom level.showMapTypes
: bool - Whether to show map types (default isfalse
).showBuildings
: bool - Whether to show buildings in 3D view (default istrue
).showZoomControls
: bool - Whether to show zoom controls (default isfalse
).canZoom
: bool - Whether zoom is enabled (default istrue
).canRotate
: bool - Whether rotation is enabled (default istrue
).searchHint
: String - Hint text for the search bar (default is"Search for location, landmarks..."
).sessionToken
: String - Optional session token for Google Places API requests.
Permissions #
Ensure you have added the required permissions for location access in your app.
For Android, add the following to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
For iOS, add these to your Info.plist
:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your custom message here</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your custom message here</string>
Contribution #
Contributions are welcome! Feel free to submit issues, feature requests, or pull requests.
License #
This package is licensed under the MIT License. See the LICENSE file for more details.