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

插件详情v0.0.6

search_map_location

search_map_location 是一个文本搜索小部件,用于通过名称搜索地理位置。它具有多个回调和自定义选项,用于处理地点搜索。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
99
喜欢数
35
Pub 分数
130

安装插件

flutter pub add search_map_location

插件介绍

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

search_map_location 是一个 Flutter 包,提供了一个文本搜索小部件,用于通过名称查找地理位置。它支持自定义 UI,并提供多种回调选项来管理地点搜索结果,非常适合将位置搜索功能集成到应用程序中。该包可在 Android、iOS、Web、macOS、Windows 和 Linux 上运行,确保所有平台上的用户体验一致。

适合场景

  • 在旅行应用中集成位置搜索
  • 在配送或物流应用中查找地点
  • 增强表单中的地址输入
  • 启用基于地图的位置选择
  • 支持事件规划应用中的地理位置功能

主要特点

  • 基于文本的位置搜索
  • 可自定义的搜索控件
  • 多个回调处理程序
  • 跨平台兼容性
  • 实时地点建议
  • 轻松集成地图

适合对象

  • 开发位置感知应用的开发者
  • 需要地址或位置输入的应用
  • 需要地图交互的项目
  • 跨平台移动和Web应用
  • 以用户体验为中心的表单设计

使用建议

  • 需要互联网连接进行地理编码
  • 可能需要 API 密钥才能实现完整功能
  • 性能取决于网络速度
  • 仅限基于名称的搜索
  • 自定义样式可能需要额外的代码
  • 依赖于底层地图服务

原始 README

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

search_map_location

search_map_location is a text search widget used to search geo location by name.It has severel call back and customization option to handle the place search.

Getting Started

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

dependencies:
    search_map_location: 0.0.6

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

  • Places

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

import 'package:search_map_location/search_map_location.dart';
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: SearchLocation(
        apiKey: // YOUR GOOGLE MAPS API KEY
        onSelected: (Place place){
        print(place.description);

         },
      )
    )
  );
}

The constructor has 8 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
  • String country you can allow the search work only for a specific country.While using country don't use location and radius .Use ISO(Use alpha 2) code for country name see iso code of countries
  • 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 place.geolocation;

Example

Here's an example of the widget using country :

return SearchLocation(
    apiKey: YOUR_API_KEY,
    // The language of the autocompletion
    language: 'en',
    //Search only work for this specific country
    country: 'BD',
    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));
    },
);

Here's an example of the widget using location and radius :

return SearchLocation(
    apiKey: YOUR_API_KEY,
    // The language of the autocompletion
    language: 'en',
    // location is the center of a place and the radius provided here are between this radius of this place search result
    //will be provided,you can set this LatLng dynamically by getting user lat and long in double value
    location: LatLng(latitude: 9.072264, longitude: 7.491302),
    radius: 1100,
    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));
    },
);

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。