MKMapView setRegion最小跨度

时间:2014-07-01 19:35:02

标签: ios mkmapview mapkit mkmapviewdelegate

我正在使用MKMapView在地图上显示一些资产。这些资产可以集群化。当用户点击群集时,我会根据群集中资产的位置计算MKCoordinateRegion,然后缩放地图:

- (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 个答案:

答案 0 :(得分:1)

其他人已经回答了,但是很难找到。使用MKMapCamera,您可以缩小到100英尺或更小。

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