正如我从文档中所理解的那样只有来自MKMapView的Real sublussing。是否可以将Realm群集与GoogleMaps一起使用,或者我应该寻找其他一些SDK?
答案 0 :(得分:0)
目前ABFRealmMapView旨在与MKMapView
配合使用,但可以扩展为使用Google Maps SDK。
实际进行群集的内部组件是:ABFLocationFetchedResultsController。这允许您创建描述地图搜索的ABFLocationFetchRequest
,然后它将获取这些对象,无论是否启用了群集。您可以复制班级ABFRealmMapView实际使用ABFLocationFetchedResultsController
的方式,并将其移植到Google地图视图的子类中。
导入代码位于refreshMapView
方法中,该方法会自动调用(如果已启用autorefresh
)以响应要移动的地图:
- (void)refreshMapView
{
@synchronized(self) {
[self.mapQueue cancelAllOperations];
MKCoordinateRegion currentRegion = self.region;
ABFLocationFetchRequest *fetchRequest =
[ABFLocationFetchRequest locationFetchRequestWithEntityName:self.entityName
inRealm:self.realm
latitudeKeyPath:self.latitudeKeyPath
longitudeKeyPath:self.longitudeKeyPath
forRegion:currentRegion];
if (self.basePredicate) {
NSCompoundPredicate *compPred =
[NSCompoundPredicate andPredicateWithSubpredicates:@[fetchRequest.predicate,self.basePredicate]];
fetchRequest.predicate = compPred;
}
[self.fetchResultsController updateLocationFetchRequest:fetchRequest
titleKeyPath:self.titleKeyPath
subtitleKeyPath:self.subtitleKeyPath];
typeof(self) __weak weakSelf = self;
NSBlockOperation *refreshOperation = [[NSBlockOperation alloc] init];
NSBlockOperation __weak *weakOp = refreshOperation;
MKMapRect visibleMapRect = self.visibleMapRect;
ABFZoomLevel currentZoomLevel = ABFZoomLevelForVisibleMapRect(visibleMapRect);
if (self.clusterAnnotations &&
currentZoomLevel <= self.maxZoomLevelForClustering) {
MKZoomScale zoomScale = MKZoomScaleForMapView(self);
[refreshOperation addExecutionBlock:^{
if (![weakOp isCancelled]) {
[weakSelf.fetchResultsController performClusteringFetchForVisibleMapRect:visibleMapRect
zoomScale:zoomScale];
[weakSelf addAnnotationsToMapView:weakSelf.fetchResultsController.annotations];
[weakSelf registerChangeNotification:weakSelf.autoRefresh];
}
}];
}
else {
[refreshOperation addExecutionBlock:^{
if (![weakOp isCancelled]) {
[weakSelf.fetchResultsController performFetch];
[weakSelf addAnnotationsToMapView:weakSelf.fetchResultsController.annotations];
[weakSelf registerChangeNotification:weakSelf.autoRefresh];
}
}];
}
[self.mapQueue addOperation:refreshOperation];
}
}