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

插件详情v2.0.7

flutter_geofire

一个 Flutter 插件,用于获取附近地点的实时更新。GeoFire 是一个开源库,可让您根据地理位置存储和查询一组键。

AndroidiOS
近 30 天下载
434
喜欢数
106
Pub 分数
130

安装插件

flutter pub add flutter_geofire

插件介绍

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

Flutter GeoFire 是一个 Flutter 插件,可使用 GeoFire(一个开源库)实现基于地理位置的实时查询。它允许开发者根据地理坐标存储和检索数据,非常适合需要附近地点检测的应用程序。通过与 Firebase 集成,它支持用户移动时的实时更新,确保准确且动态的位置跟踪。该插件简化了移动应用中的地理空间操作,特别是涉及地图或邻近警报的应用。

适合场景

  • 实时位置跟踪
  • 查找附近的兴趣点
  • 实时拼车服务
  • 基于位置的通知
  • 地理围栏实现

主要特点

  • 实时地理位置更新
  • 与 Firebase 集成
  • 支持 Android 和 iOS
  • 高效的空间查询
  • 附近位置筛选

适合对象

  • 需要基于接近度功能的应用程序
  • 网约车或配送平台
  • 社交网络与位置共享
  • 事件发现应用
  • 位置感知的物联网应用

使用建议

  • 需要 Firebase 设置
  • 限于地理空间查询
  • 依赖网络连接
  • 可能影响电池续航
  • 需要正确的权限处理

原始 README

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

flutter_geofire

A Flutter plugin to use the GeoFire Api

For Flutter plugins for other products, see mrdishant@github

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

iOS Installation

In your project's pod file add the below line

pod 'GeoFire', :git => 'https://github.com/mrdishant/geofire-objc'

Example:

            target 'Runner' do
            use_frameworks!
            use_modular_headers!
            pod 'GeoFire', :git => 'https://github.com/mrdishant/geofire-objc'
            
            flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
            end

Usage

GeoFire — Realtime location queries with Firebase.

GeoFire is an open-source library that allows you to store and query a set of keys based on their geographic location.

At its heart, GeoFire simply stores locations with string keys. Its main benefit however, is the possibility of querying keys within a given geographic area - all in realtime.

GeoFire uses the Firebase database for data storage, allowing query results to be updated in realtime as they change. GeoFire selectively loads only the data near certain locations, keeping your applications light and responsive, even with extremely large datasets.

Quickstart

Initalize GeoFire with path to keys in Realtime Database

String pathToReference = "Sites";
Intializing geoFire
Geofire.initialize(pathToReference);

Also don't forget to add indexOn in your Realtime Database rules

Example: Just change the 'Sites' with your pathToReference

    {
      "rules": {
        ".read":true,
        ".write": true,
          "Sites": {
          ".indexOn": ["g"]
        }
      }
    }   
Setting location data

Here setLocation method is used and first is the unique id of the place and other two parameters are latitude and longitude of that place.

bool response = await Geofire.setLocation(
        new DateTime.now().millisecondsSinceEpoch.toString(),
        30.730743,
        76.774948)
Retrieving a location

Retrieving a location for a single key in GeoFire happens like below:

Map<String, dynamic> response =
        await Geofire.getLocation("AsH28LWk8MXfwRLfVxgx");

print(response);
Geo Queries

GeoFire allows you to query all keys within a geographic area using GeoQuery objects. As the locations for keys change, the query is updated in realtime and fires events letting you know if any relevant keys have moved. GeoQuery parameters can be updated later to change the size and center of the queried area.

Geofire.queryAtLocation(30.730743, 76.774948, 5).listen((map) {
        print(map);
        if (map != null) {
          var callBack = map['callBack'];

          //latitude will be retrieved from map['latitude']
          //longitude will be retrieved from map['longitude']

          switch (callBack) {
            case Geofire.onKeyEntered:
              keysRetrieved.add(map["key"]);
              break;

            case Geofire.onKeyExited:
              keysRetrieved.remove(map["key"]);
              break;

            case Geofire.onKeyMoved:
            // Update your key's location
              break;

            case Geofire.onGeoQueryReady:
            // All Intial Data is loaded
            print(map['result'])

              break;
          }
        }

        setState(() {});
Stop Listening to Geo Query

To remove listeners to all queries:

bool response = await Geofire.stopListener();

print(response);

Removing a location

To remove a location and delete it from the database simply pass the location's key to removeLocation:

bool response = await Geofire.removeLocation("AsH28LWk8MXfwRLfVxgx");

print(response);                

Contributing

if you want to contribute to GeoFire, clone the repository and just start making pull requests.

git clone 'https://github.com/mrdishant/flutter_geofire'
This plugin is in development and suggestions are most welcome. Happy Coding and Be Exceptional !!

所属分类

源码仓库

使用此插件的项目

暂无相关数据。