我在 iOS 上使用 Firebase 的 Geofire 我正在从我的 firebase 数据库中获取加载数据,但如果位置有点远,它不会在地图中显示为 MKAnnotation....
我需要一种方法来过滤它应该搜索的半径..我看了geo queryAtRegion:
,但它不是应该使用的..
代码是
[[FIRAuth auth] addAuthStateDidChangeListener:^(FIRAuth * _Nonnull auth, FIRUser * _Nullable user) {
[self.geo setLocation:[[CLLocation alloc] initWithLatitude: lat longitude:log] forKey:[NSString stringWithFormat:@"%@", user.displayName] withCompletionBlock:^(NSError *error) {
if (error){
NSLog(@"%@", error.localizedDescription);
} else {
}
}];
}];
而对于获取是这个..
- (void)loadData{
self.regionQuery = [self.geo queryWithRegion:region];
NSDate *methodStart = [NSDate date];
[_regionQuery observeEventType:GFEventTypeKeyEntered withBlock:^(NSString *key, CLLocation *location) {
pinAnnotation = [[Pin alloc] init];
[pinAnnotation setKey: key];
[pinAnnotation setCoordinate:location.coordinate];
[pinAnnotation setTitle: [NSString stringWithFormat:@"%f",location.coordinate.latitude]];
[pinAnnotation setSubtitle:keyy];
[self.mapView addAnnotation:pinAnnotation];
self.annotations[key] = pinAnnotation;
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);
}];
}