2014-07-01 28 views
2

我正在使用MKMapView在地圖上顯示一些資產。這些資產可以聚集在一起。當用戶點擊一個羣集我計算基於集羣中的資產的位置MKCoordinateRegion上再放大地圖:MKMapView setRegion最小跨度

- (void)collectionView:(UICollectionView *)cv didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
    NSIndexSet *indexSet = self.aggregates[indexPath.section]; 
    NSArray *assets = [self.assetsFetchResults objectsAtIndexes:indexSet]; 

    if(assets.count == 1){ 
     [self performSegueWithIdentifier:VWWSegueCollectionToFull sender:indexPath]; 
    } else { 
     MKCoordinateRegion region = [self calculateRegionFromAssets:assets]; 
     NSLog(@"Current mapView.region: %f,%f", self.mapView.region.span.latitudeDelta, self.mapView.region.span.longitudeDelta); 
     NSLog(@"Calculated map region: %f,%f", region.span.latitudeDelta, region.span.longitudeDelta); 
     [self.mapView setRegion:region animated:YES]; 
    } 
} 

即使我的功能正確計算區域,地圖上只有放大到一定的水平。用戶可以在沒有問題的情況下進一步捏合和放大,但不會讓我以編程方式靠近。以編程方式,最小跨度似乎約爲0.008x0.008。

這裏是我的代碼輸出,當用戶第一次縮小,那麼集羣被竊聽:然後

2014-07-01 12:26:46.123 [6090:1074617] Current mapView.region: 0.407665,0.412912 
2014-07-01 12:26:46.124 [6090:1074617] Calculated map region: 0.000750,0.000755 

的代碼無法放大到大小0.000750,0.000750的跨度。

2014-07-01 12:26:50.330 [6090:1074617] Current mapView.region: 0.008123,0.008240 
2014-07-01 12:26:50.331 [6090:1074617] Calculated map region: 0.000750,0.000755 

並再次嘗試,同樣。

2014-07-01 12:26:53.349 [6090:1074617] Current mapView.region: 0.008123,0.008240 
2014-07-01 12:26:53.350 [6090:1074617] Calculated map region: 0.000750,0.000755 

我慢慢增加了我的函數輸出的最小跨度,但沒關係。地圖不會放大。

如果我不能找到一個方法來得到這個工作,我會看看設置MKCamera

回答

1

它已經被人回答了,但還算很難找到SO。使用MKMapCamera,您可以縮小至100英尺或更小。

MKMapCamera *myCamera = [MKMapCamera cameraLookingAtCenterCoordinate:newLocation 
               fromEyeCoordinate:newLocation eyeAltitude:50]; 
[_appleMap setCamera:myCamera animated:false];