2

是否可以使用 Firebase 的 GeoFire 检索特定范围内的所有密钥?我知道您可以接收地理查询事件,例如:输入键、退出键或移动键,但是我目前正在寻找更像 FEventTypeValue 的东西(针对特定地理区域读取一次值),因为我的地图对象不动。

在文档中找不到任何内容:https ://github.com/firebase/geofire-objc

4

2 回答 2

2

您可以使用键输入事件首先将查询的所有键保存在字典中,然后使用就绪事件来确定何时添加了所有键:

NSMutableDictionary *allKeys = [NSMutableDictionary dictionary];
[query observeEventType:GFEventTypeKeyEntered withBlock:^(NSString *key, CLLocation *location) {
    [allKeys setObject:location forKey:key];
}];
[query observeReadyWithBlock:^{
    // Create an immutable copy of the keys in the query
    NSDictionary *valueData = [allKeys copy];
    NSLog(@"All keys within a query: %@", valueData);
}];

之后不要忘记清理你的听众。

于 2015-03-09T19:24:20.510 回答
-1

这不正是你要找的吗?

GeoFire 允许您使用 GFQuery 对象查询地理区域内的所有键。

目标-C:

  CLLocation *center = [[CLLocation alloc] initWithLatitude:37.7832889 longitude:-122.4056973];
    // Query locations at [37.7832889, -122.4056973] with a radius of 600 meters
    GFCircleQuery *circleQuery = [geoFire queryAtLocation:center withRadius:0.6];

    // Query location by region
    MKCoordinateSpan span = MKCoordinateSpanMake(0.001, 0.001);
    MKCoordinateRegion region = MKCoordinateRegionMake(center.coordinate, span);
    GFRegionQuery *regionQuery = [geoFire queryWithRegion:region];

迅速:

let center = CLLocation(latitude: 37.7832889, longitude: -122.4056973)
// Query locations at [37.7832889, -122.4056973] with a radius of 600 meters
var circleQuery = geoFire.queryAtLocation(center, withRadius: 0.6)

// Query location by region
let span = MKCoordinateSpanMake(0.001, 0.001)
let region = MKCoordinateRegionMake(center.coordinate, span)
var regionQuery = geoFire.queryWithRegion(region)
于 2015-03-09T14:13:03.400 回答