获取GeoFire中特定范围内的所有对象

时间:2015-03-09 13:30:29

标签: ios objective-c firebase geofire

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

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

2 个答案:

答案 0 :(得分:2)

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

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);
}];

之后不要忘记清理听众。

答案 1 :(得分:-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)