2013-07-01 76 views
0

我在使用IOS6的MapView上遇到最大缩放级别问题。用户可以放大得太多,并且瓷砖是空白的。IOS6 MKMapView最大缩放级别

速战速决是要做到这一点:

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

,并再次自动缩小,但有时还是会放大太远,不会再次缩小。

我想我需要获得当前区域的最大缩放级别,但似乎并没有这样做的简单方法。你们是如何克服这个问题的?

回答

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

也许它并不完美,但它不够好,我需要的东西。

0

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