搜尋套件、儲存庫與 APP 分類

套件詳情v0.3.0

search_map_place

一個搜尋小工具,讓使用者在搜尋地點時獲得自動補完的回饋。

近 30 天下載
107
喜歡數
58
Pub 分數
30

安裝套件

flutter pub add search_map_place

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 小部件,允許使用者透過即時自動完成建議搜尋地點。專為簡化需要地址或地點選擇之應用程式中的位置輸入而設計,可無縫整合至表單與地圖中。該套件提供乾淨直覺的介面,供輸入與選擇地點,提升使用者在輸入地點時的體驗。支援使用者輸入時的動態回饋,減少錯誤並提升效率。以簡單性與效能為核心建構,非常適合需要快速且精確地點輸入的應用。

適用情境

  • 基於位置的應用搜尋
  • 表單中的地址輸入
  • 地圖標記位置
  • 旅行與配送應用
  • 地理位置表單欄位

主要特色

  • 即時自動補全
  • 簡單整合
  • 使用者友好的介面
  • 輸入時的動態反饋
  • 輕量且快速

適合對象

  • 具有位置功能的移動應用
  • 需要地址選擇的應用
  • 開發者尋找便捷的地點搜尋
  • 以使用者體驗為導向的位置輸入
  • 極簡設計要求

使用建議

  • 需要網路連接以實現自動補全
  • 有限的自訂選項
  • 無離線支援
  • 依賴外部地理編碼服務
  • 可能需要額外的樣式以實現主題對齊

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

search_map_place

This is a Flutter package that uses the Google Maps API to make a TextField that tries to autocomplete places as the user types, with simple smooth animations, providing a nice UI and UX. This will also provide great information about the user selected place, like the coordinates, the bounds to determine the zoom of the GoogleMap widget, and so on.

example

This is an example of what can be done using this package. To see the source code, check the examples folder.

Getting Started

To install, add it to your pubspec.yaml file:

dependencies:
    search_map_place: <latest>

After that, make sure you have the following APIs activated in your Google Cloud Platform:

  • Places
  • Geolocation
  • Geocoding

You can now import it to your file and use it on your app.

import 'package:search_map_place/search_map_place.dart';

How to use it

Where you want to add the search widget, call SearchMapPlaceWidget's constructor:

Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: SearchMapPlaceWidget(
        apiKey: // YOUR GOOGLE MAPS API KEY
      )
    )
  );
}

The constructor has 7 attributes related to the API:

  • String apiKey is the only required attribute. It is the Google Maps API Key your application is using
  • (Place) void onSelected is a callback function called when the user selects one of the autocomplete options.
  • (Place) void onSearch is a callback function called when the user clicks on the search icon.
  • String language is the Language used for the autocompletion. Default is 'en' (english). Check the full list of supported languages for the Google Maps API
  • LatLng location is the point around which you wish to retrieve place information. If this value is provided, radius must be provided aswell.
  • int radius is the distance (in meters) within which to return place results. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area. If this value is provided, location must be provided aswell. See Location Biasing and Location Restrict in the Google Maps API documentation.
  • bool restrictBounds will return only those places that are strictly within the region defined by location and radius.
  • PlaceType placeType will allow you to filter Places by its type. For more information on available types, check supported types for Autocompletion. On default, no filters are passed to the request, which means all Place types will be shown on autocompletion.
The Place class

This class will be returned on the onSelected and onSearch methods. It allows us to get more information about the user selected place.

Initially, it provides you with only basic information:

  • description contains the human-readable name for the returned result. For establishment results, this is usually the business name.
  • placeIdA textual identifier that uniquely identifies a place. For more information about place IDs, see the Place IDs overview.
  • types contains an array of types that apply to this place. The array can contain multiple values. Learn more about Place types.
  • fullJSON has the full JSON response received from the Places API. Can be used to extract extra information. More info on the Places Autocomplete API documentation

However, you can get more information like the coordinates and the bounds of the place by calling

await myPlace.geolocation;

Example

Here's an example of the widget being used:

return SearchMapPlaceWidget(
    apiKey: YOUR_API_KEY,
    // The language of the autocompletion
    language: 'en',
    // The position used to give better recomendations. In this case we are using the user position
    location: userPosition.coordinates,
    radius: 30000,
    onSelected: (Place place) async {
        final geolocation = await place.geolocation;

        // Will animate the GoogleMap camera, taking us to the selected position with an appropriate zoom
        final GoogleMapController controller = await _mapController.future;
        controller.animateCamera(CameraUpdate.newLatLng(geolocation.coordinates));
        controller.animateCamera(CameraUpdate.newLatLngBounds(geolocation.bounds, 0));
    },
);

Future Implementations

There are a lot of features that can be added to this package. Here are some features I want to implement (or could be implemented by someone else):

  • [ ] Make the widget more personalizable
  • [ ] Make this package independent of google_maps_flutter
  • [ ] Allow users to close the box clicking outside of it
  • [ ] Proper widget dimensions for phones in portrait orientation or foldables.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案