2015-10-07 37 views
0

由于某些原因,如果半径设置为1197或更高,我的Geofire查询仅返回物品。更少,也不会返回任何内容。当数据返回并记录距离时,它们都小于1km,所以这对我没有任何意义。当设置巨大半径时,Firebase Geofire查询仅返回附近的物品

这个的任何想法?

代码:

this.firebaseRef = new Firebase("<my firebase - this is fine>"); 
    this.geoFire = new GeoFire(this.firebaseRef); 

    this.geoQuery = this.geoFire.query({ 
    center: [50.72001, -1.8800], 
    radius: 1197 
    }); 

    this.geoQuery.on("key_entered", function(key, location, distance){ 
    console.log(key + ', ' + location + ', ' + distance); 
    }); 

我要提到我使用的反应,这是在componentWillMount方法。

谢谢!

更新: Geofire似乎需要一个Geohash来搜索数据库,所以要解决我的问题,我开始将lat/lng转换为geohashes并将其存储。

+0

GeoFire提供了用于保存应该以您的名义创建geohash的lat/long的方法。这些可能会有所帮助。 – Kato

回答

0

Geofire似乎需要一个Geohash来搜索数据库,而我的只存储了经度和纬度,所以为了解决我的问题,我开始将lat/lng转换为geohashes并存储起来。

将坐标转换为地理散列,看到https://github.com/chrisveness/latlon-geohash,这完美地工作。

+0

使用Javascript有可能吗?搜索静态(固定)位置附近的密钥(密钥列表) - 这些位置是在Firebase数据存储中预先添加的。 注意:不使用'key_entered',因为'key_entered'仅在新的或位置更新时触发。以前添加的地点,但在给定的半径范围内。 怎么可能? –

+0

是的,这绝对有可能使用Geofire。我建议您查看相关文档,因为我没有在Geofire工作一年多,所以不记得如何去做。 – sherlock

+0

不,没有找到!请检查此问题的详细信息:http://stackoverflow.com/questions/43632746/firebase-geofire-js-how-to-get-list-of-keys-of-near-by-staticfixed-locations –