2016-05-21 22 views

Antwort

0

Im Moment ist ABFRealmMapView entworfen, um mit MKMapView zu arbeiten, aber es könnte erweitert werden, um mit Google Maps SDK zu arbeiten.

Die interne Komponente, die das Clustering tatsächlich durchführt, ist: ABFLocationFetchedResultsController. Auf diese Weise können Sie eine ABFLocationFetchRequest erstellen, die die Kartensuche beschreibt, und dann diese Objekte holen, entweder mit aktiviertem Clustering oder nicht. Sie könnten kopieren, wie die Klasse ABFRealmMapView tatsächlich ABFLocationFetchedResultsController verwendet und diese in eine Unterklasse der Google-Kartenansicht portiert.

Der Import-Code ist in der refreshMapView Methode, die automatisch aufgerufen wird (wenn autorefresh aktiviert ist) in Reaktion auf die Karte bewegt wird:

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