Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Geofire如何计算Firebase查询的边界GeoHash?_Javascript_Firebase_Firebase Realtime Database_Geofire_Geohashing - Fatal编程技术网

Javascript Geofire如何计算Firebase查询的边界GeoHash?

Javascript Geofire如何计算Firebase查询的边界GeoHash?,javascript,firebase,firebase-realtime-database,geofire,geohashing,Javascript,Firebase,Firebase Realtime Database,Geofire,Geohashing,上下文 我在Firebase中使用Geofire已有一段时间了,我非常好奇Geofire是如何执行查询的。我理解在语义上,它是坐标和半径的函数,导致最小和最大散列。因此,我认为它与Firebase协同工作的方式如下所示 ref.child("users").orderByChild("g").startAt(minHash).endAt(maxHash).on('child_added', function(snapshot) { /* retrieved snapshot contains t

上下文

我在Firebase中使用Geofire已有一段时间了,我非常好奇Geofire是如何执行查询的。我理解在语义上,它是坐标和半径的函数,导致最小和最大散列。因此,我认为它与Firebase协同工作的方式如下所示

ref.child("users").orderByChild("g").startAt(minHash).endAt(maxHash).on('child_added', function(snapshot) { /* retrieved snapshot contains the geohashes in range */ });
其中,这两个(最小和最大)geohash是根据给定的输入计算的。现在问题来了

问题

假设我上面所说的是正确的,那么这两个geohash是如何计算的呢?当GeoHash通常表示边界矩形时,它们如何在特定的圆形区域内返回结果?最后,两个不同大小的geohash如何具有相同的中心

对最后一部分进行澄清:考虑下面的图像

既然geohashing通过将区域减半为更小的区域来工作,那么两个不同大小的散列(最小值和最大值)如何具有相同的中心点

假设


我认为可能只是简单地增加/减少散列的原始值,但这没有多大意义,因为增加/减少应该与散列的大小(“缩放”级别)和查询半径相关,如果我没弄错的话。

GeoFire实际上是对数据库执行矩形区域的范围查询。此范围是包含查询中指示范围的最小矩形

然后,它在客户端代码中检查每个键到查询中心的实际距离,并仅为查询中的项目触发
key\u entered
/
key\u moved
事件

有关守则如下:

//确定位置是否在此查询中
distanceFromCenter=GeoFire.distance(位置,中心);
isInQuery=(距离中心
// Determine if the location is within this query
distanceFromCenter = GeoFire.distance(location, _center);
isInQuery = (distanceFromCenter <= _radius);

...

// Fire the "key_entered" event if the provided key has entered this query
if (isInQuery && !wasInQuery) {
  _fireCallbacksForKey("key_entered", key, location, distanceFromCenter);
} else if (isInQuery && oldLocation !== null && (location[0] !== oldLocation[0] || location[1] !== oldLocation[1])) {
  _fireCallbacksForKey("key_moved", key, location, distanceFromCenter);
} else if (!isInQuery && wasInQuery) {
  _fireCallbacksForKey("key_exited", key, location, distanceFromCenter);
}