2016-05-21 2 views

答えて

0

今のところABFRealmMapViewMKMapViewで動作するように設計されていますが、Google Maps SDKと連携するように拡張することもできます。

実際にクラスタリングを実行する内部コンポーネントは、ABFLocationFetchedResultsControllerです。これにより、マップ検索を記述するABFLocationFetchRequestを作成し、クラスタリングを有効にした状態でこれらのオブジェクトをフェッチします。 ABFRealmMapViewクラスが実際にABFLocationFetchedResultsControllerをどのように使用しているかをコピーして、これをGoogleマップビューのサブクラスに移植することができます。

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

インポートコードは(autorefreshが有効な場合)に移動されるマップに応答して自動的に呼び出されrefreshMapView方法、です

関連する問題