IOS6 MKMapView最大缩放级别

时间:2013-07-01 12:30:45

标签: ios6 mkmapview

我在使用IOS6的MapView上遇到最大缩放级别时出现问题。用户可以放大太多而且图块是空白的。

快速修复是这样做的:

- (void)mapView:(MKMapView *)theMapView regionDidChangeAnimated:(BOOL)animated {
    if([theMapView zoomLevel] > 18) {
        [theMapView setCenterCoordinate:[theMapView centerCoordinate] zoomLevel:18 animated:TRUE];
    }
}

并自动再次缩小,但有时它仍会缩放太远并且不会再次缩小。

我想我需要获得当前所在区域的最大缩放级别,但似乎没有一种简单的方法可以做到这一点。你们是怎么解决这个问题的?

2 个答案:

答案 0 :(得分:0)

修复就是做这样的事情:

- (void)setRegionWithMaximumZoomLevel:(MKCoordinateRegion)region animated:(BOOL)animated
{
    if ([self zoomLevelForRegion:region] > 17)
    {
        [self setCenterCoordinate:region.center zoomLevel:17 animated:TRUE];
    }else
    {
        [self setRegion:region animated:animated];
    }
}

- (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate
                  zoomLevel:(NSUInteger)zoomLevel
                   animated:(BOOL)animated
{
    // clamp large numbers to 28
    zoomLevel = MIN(zoomLevel, 17);

    // use the zoom level to compute the region
    MKCoordinateSpan span = [self coordinateSpanWithMapView:self centerCoordinate:centerCoordinate andZoomLevel:zoomLevel];
    MKCoordinateRegion region = MKCoordinateRegionMake(centerCoordinate, span);

    // set the region like normal
    [self setRegion:region animated:animated];
}

也许它并不完美,但它足以满足我的需要。

答案 1 :(得分:0)

我确实遇到了和你一样的问题,这是iOS6.0的错误,这很难。您的程序不应该有iOS 5.0中的空白问题,希望苹果可以修复它。 gitHub中的MKMapView + ZoomLevel是设置mapView的缩放级别的一个很好的工具,但是你也会遇到一些麻烦的瓷砖空白问题。但是,这可能会对你有所帮助: https://github.com/DeepFriedTwinkie/iOS6MapZoomIssue