一個 Flutter 套件,利用 MapBox API 提供地點搜尋功能並產生靜態地圖影像。它透過提供直觀的介面,簡化了在 Flutter 應用中整合地理定位功能的過程,支援搜尋位置、取得座標以及顯示靜態地圖。非常適合需要地址查詢、位置選擇或地圖預覽的應用程式。此套件支援 Android、iOS、Web、macOS、Windows 與 Linux 多個平台,確保廣泛的相容性。開發者可輕鬆實作基於位置的服務,且設定簡單。
適用情境
移動應用中的位置搜尋
表單地址選擇器
靜態地圖預覽
地理編碼整合
基於地圖的使用者介面元件
旅行與配送應用
主要特色
MapBox API 結合
靜態地圖影像產生
跨平台支援
簡單搜尋介面
座標檢索
響應式設計
適合對象
開發位置感知應用的開發者
需要地址查詢的應用
需要靜態地圖的專案
跨平台行動與網頁應用程式
旅行、物流與地圖工具
使用建議
需要 MapBox API 金鑰
需要網絡連接
免費層級上的潛在速率限制
搜尋UI的自訂選項有限
依賴外部API的穩定性
每個平台的額外設定
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
About
Note: Breaking Changes in 4.x.x
PlaceSearch and ReverseGeoCoding classes are now merged into one class called GeoCoding with two methods getPlaces and getAddress since both of them are using the same API.
Instead of throwing exceptions, the package now returns ApiResponse Record which can be either Success or Failure and can be handled using fold method.
Location class is now converted to a record.
List of coordinates are now converted to a record (lat: double, long: doube) whereever possible.
This package provides easy api calls to MapBox Search API.
As this package doesn't depend on Flutter SDK you cannot use the Colors class anymore on you Flutter project.
Instead use map_box_search's Color.rgb constructor, passing the values as parameters:
var myColor = Colors.redAccent; //Flutter's Color classvar mapBoxColor = Color.rgb( myColor.red, myColor.green, myColor.blue);
Installing
First of all you must acquire an API key on the MapBox website https://www.mapbox.com/
Then, add the following to your pubspec.yaml file:
dependencies:
mapbox_search: any
Setup
Now you can setup the API key for whole app by calling MapBoxSearch.init('API KEY') in your main() function, this way you don't have to pass the API key to every class that uses the package.
Usage of ApiResponse
finalApiResponse<List<MapBoxPlace>> addresses = awaitgetAddress();
addresses.fold(
(success) => // Do something with success data,
(failure) => // Do something with failure data,
);
Examples
SearchBox API
SearchBoxAPI search = SearchBoxAPI(
apiKey: 'API Key', // dont pass if you have set it in MapBoxSearch.init('API KEY')
limit: 6,
);
var reverseGeoCoding = GeoCoding(
apiKey: 'API Key', // dont pass if you have set it in MapBoxSearch.init('API KEY')
limit: 5,
);
Future<ApiResponse<List<MapBoxPlace>>> getAddress() =>
reverseGeoCoding.getAddress(
Location(lat: 72.0, lng: 76.00),
);
Forward GeoCoding Seach
var geocoding = GeoCoding(
apiKey: 'API Key', // dont pass if you have set it in MapBoxSearch.init('API KEY')
country: "BR",
limit: 5,
types: [PlaceType.address, PlaceType.place],
);
Future<ApiResponse<List<MapBoxPlace>>> getPlaces() =>
geocoding.getPlaces(
"central park",
proximity: Location(
lat: -19.984634,
lng: -43.9502958,
),
);
Batch Geocoding (v6)
Perform multiple geocoding queries (forward, reverse, or structured) in a single request.