一個 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