Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blackmann/locationpicker
Location picker for Flutter.
https://github.com/blackmann/locationpicker
dart flutter maps
Last synced: 5 days ago
JSON representation
Location picker for Flutter.
- Host: GitHub
- URL: https://github.com/blackmann/locationpicker
- Owner: blackmann
- License: other
- Created: 2019-06-01T08:59:54.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-14T03:12:07.000Z (3 months ago)
- Last Synced: 2024-10-15T03:05:22.897Z (22 days ago)
- Topics: dart, flutter, maps
- Language: Dart
- Size: 1.19 MB
- Stars: 169
- Watchers: 4
- Forks: 160
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flutter Place Picker [![Pub](https://img.shields.io/pub/v/place_picker.svg)](https://pub.dev/packages/place_picker)
The missing location picker made in Flutter for Flutter. With dark theme and custom localization support.
⚠️ Please note: This library will NOT be affected by the deprecation of Place Picker as [indicated here](https://developers.google.com/places/android-sdk/placepicker).
🍭 Remember to enable `Places API`, `Maps SDK for Android`, `Maps SDK for iOS` and `Geocoding API` for your API key.
## Usage
To use this plugin, add `place_picker` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
## Getting Started
This package relies on [google_maps_flutter](https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter) to display the map. Follow these guidelines to add your API key to the Android and iOS packages.
Get an API key at if you haven't already.
### Android
Specify your API key in the application manifest `android/app/src/main/AndroidManifest.xml` and add `ACCESS_FINE_LOCATION` permission:
```xml
```
Update your gradle.properties file with this:
```groovy
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
```Please also make sure that you have those dependencies in your build.gradle:
```groovy
// parent level build.gradle (android/build.gradle)
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.2.0'
}
...// app level build.gradle (android/app/build.gradle)
compileSdkVersion 28
```### iOS
Specify your API key in the application delegate `ios/Runner/AppDelegate.m`:
```objectivec
#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`:
```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`.![info.plist](https://i.ibb.co/hWN3Y75/plist.png "Place inside the dict values")
Also add these to the dict values in `Info.plist` for location request to work on iOS
![info.plist](https://i.ibb.co/2Y3X2jY/locationperm.png)## Sample Usage
Import the package into your code
```dart
import 'package:place_picker/place_picker.dart';
```Create a method like below, and call it in `onTap` of a button or InkWell. A `LocationResult` will be returned
with the name and lat/lng of the selected place. You can then handle the result in any way you want.
Pass in an optional `LatLng displayLocation` to display that location instead. This is useful when you want the map
to display the previously selected location.```dart
void showPlacePicker() async {
LocationResult result = await Navigator.of(context).push(MaterialPageRoute(
builder: (context) =>
PlacePicker("YOUR API KEY",
displayLocation: customLocation,
)));// Handle the result in your way
print(result);
}
```