@2mann/geofire 中文文档教程

发布于 7年前 浏览 27 项目主页 更新于 3年前

FORK NOTES

这个分支的目的是允许 set 方法获取额外的数据并将其放入 firebase 节点(即:时间戳)

我们现在可以将第三个参数传递给 set带有一个对象,每个属性将被添加到 geofire 节点

ex:

export function setUserLocation (uid, coords) {
  return geoFireRef.set(uid, coords, {
    t: database.ServerValue.TIMESTAMP,
  })
}

这个有效载荷将通过 key_addedkey_moved 回调作为第四个参数浮出水面(所有原始数据将在该对象中,包括 geohash 和坐标)

例如:

this.geoQuery.on('key_entered', (key, coords, distance, payload) => {
  if (key !== this.props.currentUserId) {
    this.props.addUser({
      uid: key,
      timestamp: payload.t,
    })
  }
})

注意:它将始终且仅使用作为第三个参数传递的有效负载 如果您传递一个点数组来设置,则不支持每个节点都有自己的有效负载,它只会使用传递的任何内容作为每个节点的第三个参数。 这可以更改,但我很懒,我没有它的用​​例 ATM

GeoFire for JavaScript Build StatusCoverage StatusVersion

GeoFire 是一个开源库,允许您存储和查询一组基于它们的密钥 地理位置。 GeoFire 的核心是简单地使用字符串键存储位置。 它的主要 然而,好处是可以只检索给定地理范围内的那些密钥 区域 - 全部实时。

GeoFire 使用 Firebase 实时数据库 获取数据 存储,允许查询结果在变化时实时更新。 GeoFire 选择性加载 仅特定位置附近的数据,使您的应用程序保持轻便和响应,即使 非常大的数据集。

GeoFire 被设计为 Firebase 的轻量级插件。 为了简单起见,GeoFire 存储数据 在您的 Firebase 数据库中以其自己的格式和自己的位置。 这允许您现有的数据 格式和安全规则保持不变,同时仍然为您提供简单的地理解决方案 查询。

兼容的 GeoFire 客户端也可用于 Objective-CJava

Table of Contents

Downloading GeoFire

为了在你的项目中使用 GeoFire,你需要在你的 HTML 中包含以下文件:

<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/3.7.0/firebase.js"></script>

<!-- GeoFire -->
<script src="https://cdn.firebase.com/libs/geofire/4.1.2/geofire.min.js"></script>

使用上面的 URL 从 火力基地CDN。 您也可以从以下位置下载它们 此 GitHub 存储库的发布页面

您还可以通过 npm 或 Bower 安装 GeoFire。 如果通过 npm 下载,则必须安装 单独使用 Firebase(因为它是 GeoFire 的对等依赖项):

$ npm install geofire firebase --save

在 Bower 上,Firebase 依赖项将自动下载:

$ bower install geofire --save

Documentation

Examples

您可以找到我们演示的完整列表,并在 此存储库的 示例目录。 这些示例涵盖了一些常见用途 GeoFire 案例并说明如何使用 Firebase 数据库安全规则

Example Usage

假设您正在构建一个对酒吧进行评分的应用程序,并且您存储了酒吧的所有信息,例如名称, 营业时间和价格范围,位于 /bars/。 稍后,您想添加的可能性 用户搜索附近的酒吧。 这就是 GeoFire 的用武之地。您可以存储 使用 GeoFire 为每个栏定位,使用栏 ID 作为 GeoFire 键。 GeoFire 然后允许你 轻松查询附近有哪些酒吧 ID(钥匙)。 显示有关的任何附加信息 条形图,您可以在 /bars/ 加载查询返回的每个条形图的信息。

Migration Guides

使用旧版本的 GeoFire 并想升级到最新版本? 看看我们的 迁移指南 了解如何操作!

Contributing

如果您想为 GeoFire 做出贡献,请先通读我们的贡献 指南此处 提供了本地设置说明。

FORK NOTES

The purpose of this fork is to allow the set method to take additional data and put it in the firebase node (ie: timestamp)

We can now pass a third argument to set with an object and each property will be added to the geofire node

ex:

export function setUserLocation (uid, coords) {
  return geoFireRef.set(uid, coords, {
    t: database.ServerValue.TIMESTAMP,
  })
}

This payload will be surfaced via the key_added and key_moved callbacks as the fourth argument (all the raw data will be in that object including the geohash and coordinates)

ex:

this.geoQuery.on('key_entered', (key, coords, distance, payload) => {
  if (key !== this.props.currentUserId) {
    this.props.addUser({
      uid: key,
      timestamp: payload.t,
    })
  }
})

NOTE: it will always and only use the payload passed as the 3rd argument If you pass an array of points to set, there is no support for each node having its own payload, it will just use whatever is passed as third argument for each node. This can be changed but im lazy and i dont have a usecase for it ATM

GeoFire for JavaScript Build StatusCoverage StatusVersion

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 retrieving only those keys within a given geographic area - all in realtime.

GeoFire uses the Firebase Realtime 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.

GeoFire is designed as a lightweight add-on to Firebase. To keep things simple, GeoFire stores data in its own format and its own location within your Firebase database. This allows your existing data format and Security Rules to remain unchanged while still providing you with an easy solution for geo queries.

A compatible GeoFire client is also available for Objective-C and Java.

Table of Contents

Downloading GeoFire

In order to use GeoFire in your project, you need to include the following files in your HTML:

<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/3.7.0/firebase.js"></script>

<!-- GeoFire -->
<script src="https://cdn.firebase.com/libs/geofire/4.1.2/geofire.min.js"></script>

Use the URL above to download both the minified and non-minified versions of GeoFire from the Firebase CDN. You can also download them from the releases page of this GitHub repository.

You can also install GeoFire via npm or Bower. If downloading via npm, you will have to install Firebase separately (because it is a peer dependency to GeoFire):

$ npm install geofire firebase --save

On Bower, the Firebase dependency will be downloaded automatically:

$ bower install geofire --save

Documentation

Examples

You can find a full list of our demos and view the code for each of them in the examples directory of this repository. The examples cover some of the common use cases for GeoFire and explain how to protect your data using the Firebase Database Security Rules.

Example Usage

Assume you are building an app to rate bars and you store all information for a bar, e.g. name, business hours and price range, at /bars/<bar-id>. Later, you want to add the possibility for users to search for bars in their vicinity. This is where GeoFire comes in. You can store the location for each bar using GeoFire, using the bar IDs as GeoFire keys. GeoFire then allows you to easily query which bar IDs (the keys) are nearby. To display any additional information about the bars, you can load the information for each bar returned by the query at /bars/<bar-id>.

Migration Guides

Using an older version of GeoFire and want to upgrade to the latest version? Check out our migration guides to find out how!

Contributing

If you'd like to contribute to GeoFire, please first read through our contribution guidelines. Local setup instructions are available here.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文