一个 Flutter 包,可简化从 Google 地图中选择位置。它为用户提供了一个直观的界面,通过与地图交互来选择地点,非常适合需要精确地理定位输入的应用程序。该包与 Google 地图 SDK 无缝集成,支持自定义标记和位置详情获取。专为希望快速实现基于地图的位置选择而无需编写大量样板代码的开发者设计。
适合场景
基于地图的地址选择
表单中的位置选择器
旅行或配送应用签到
地理标记功能
用户资料位置设置
主要特点
与 Google 地图 SDK 的轻松集成
可自定义的标记和用户界面
返回详细的位置数据
支持搜索和标记放置
轻量级且专注于地点选择
适合对象
开发位置感知应用程序的开发者
需要用户选择坐标的应用
大量使用 Google 地图的项目
需要快速定位输入的原型
使用建议
需要 Google Maps API 密钥
仅限 Google 地图平台
不支持离线地图
依赖互联网连接
可能需要额外的样式以保持UI一致性
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Google Maps Pick Place
A pub.dev package to handle picking place from google map and use the picked data in the app.
On iOS you'll need to add the following entries to your Info.plist file (located under ios/Runner) in order to access the device's location.
Simply open your Info.plist file and add the following:
<key>NSLocationWhenInUseUsageDescription</key><string>This app needs access to location when open.</string><key>NSLocationAlwaysUsageDescription</key><string>This app needs access to location when in the background.</string><key>NSLocationAlwaysAndWhenInUseUsageDescription</key><string>This app needs access to location when open and in the background.</string>
In addition, you need to add the Background Modes capability to your XCode project (Project > Signing and Capabilties > "+ Capability" button) and select Location Updates.g>This app needs access to location when open and in the background.
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 can use GoogleMapsPickPlace by pushing to a new page using Navigator, OR put as a child of any widget.
When the user picks a place on the map, it will return result to 'getResult' with FullAddress type.
import'package:flutter/material.dart';
import'package:google_maps_pick_place/google_maps_pick_place.dart';
// ...Navigator.push(
context,
MaterialPageRoute(
builder: (context) => GoogleMapsPickPlace(
apiKey: "YOU GOOGLE MAPS API KEY",
getResult: (FullAddress result) {
print('${result.address}');
/// Don't use Navigator.of(context).pop() it's build in the method
},
),
),
);
Note
Searching for a place feature needs a paid google map api key.
With free key map and picking a place feature will work correctly without any error.
But searching for a place feature will not work.
Google Maps Pick Place Properties
Parameter
Type
Description
apiKey
String
Google Map Api Token
mapLanguage
Language
map's language used in search and other widgets
getResult
Function(FullAddress)?
Method of Getting the address and position
initialPosition
LatLng
Initial position of the map in case there's no location and GPS is off
enableMyLocationButton
bool
Enable or disable the My Location button
enableSearchButton
bool
Enable or disable the Search button
loader
Widget
Widget to show while the map is loading
doneButton
Widget?
Widget to show when the map is done loading and apply getResult method
errorButton
Widget?
Widget to show when there's a corruption or there's no internet connection