搜索插件、代码仓与 APP 分类

place_picker 封面
插件详情v0.10.0

place_picker

完全用 Dart 编写的适用于 Flutter 的位置选择器。包含自动补全建议和附近地点列表。也支持本地化。

近 30 天下载
322
喜欢数
147
Pub 分数
60

安装插件

flutter pub add place_picker

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

位置选择器是一个完全用 Dart 编写的 Flutter 包,用于选择位置,提供自动补全建议和附近地点列表。它支持本地化,可实现多语言用户体验。专为无缝集成到 Flutter 应用而设计,通过直观的 UI 组件简化地址和位置输入。该包利用 Google Maps 后台获取准确的地理定位数据,并通过智能建议和实时反馈提升用户体验。非常适合需要精确位置选择的应用。

适合场景

  • 表单中的地址输入
  • 配送服务的位置选择
  • 旅行和地图应用
  • 用户资料位置设置
  • 事件或场地注册

主要特点

  • 自动补全建议
  • 附近位置列表
  • 内置本地化
  • Google 地图集成
  • 完全可自定义的用户界面
  • 纯 Dart 实现

适合对象

  • 需要位置输入的移动应用
  • 面向国际用户的应用
  • 使用纯 Dart 解决方案的开发者
  • 需要轻量级位置选择器的项目
  • 带有地图功能的Flutter应用

使用建议

  • 需要 Google Maps API 密钥
  • 仅限 Google 地图后端
  • 可能需要额外的样式来支持自定义主题
  • 依赖互联网连接
  • 不适用于离线位置选择

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Place Picker Pub

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.

🍭 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.

Getting Started

This package relies on 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 https://cloud.google.com/maps-platform/ 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:

<manifest ...

  <!-- Add this permission -->
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

  <application ...
    <!-- Add your api key here -->
    <meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR KEY HERE"/>
    <activity ..../>
  </application>
</manifest>

Update your gradle.properties file with this:

android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M

Please also make sure that you have those dependencies in your build.gradle:

  // 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:

#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.

info.plist

Also add these to the dict values in Info.plist for location request to work on iOS info.plist

Sample Usage

Import the package into your code

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.

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);
}

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。