MKMapView span doubling bug

Setting the region in MKMapView occasionally results in the span being doubled. This bug seems to appear early in the map initialization phase. Although it's been reported elsewhere I wasn't able to find a descent existing workaround, so I'm posting my fix here. It relies on the fact that the regionThatFits method also produces the bug. I'm working with iPhone OS 3.12, but the bug was reported in 3.0 beta. This code lives in the UIViewController that contains your MKMapView: - (BOOL)doubleSpanBugDetected:(MKCoordinateRegion)region fittedRegion:(MKCoordinateRegion)fitted { float latRatio = fitted.span.latitudeDelta / region.span.latitudeDelta; float lonRatio = fitted.span.longitudeDelta / region.span.longitudeDelta; BOOL latDoubled = (latRatio > 1.8 && latRatio < 2.2); // within 10% of x2 BOOL lonDoubled = (lonRatio > 1.8 && lonRatio < 2.2); // within 10% of x2 return latDoubled && lonDoubled; } - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated { //fixes setRegion span doubling bug // see: http://osmorphis.blogspot.com/2009/12/mapkit-span-doubling-bug.html // see: http://www.iphonedevsdk.com/forum/iphone-sdk-development/15810-mkmapview-needs-time-think.html MKCoordinateRegion fitted = [self.mapView regionThatFits:region]; if ([self doubleSpanBugDetected:region fittedRegion:fitted]) { MKCoordinateSpan span = MKCoordinateSpanMake(fitted.span.latitudeDelta/2.0, fitted.span.longitudeDelta/2.0); MKCoordinateRegion regionHack = MKCoordinateRegionMake(fitted.center, span); [self.mapView setRegion:regionHack animated:animated]; } else { [self.mapView setRegion:fitted animated:animated]; } }
This is driving me crazy too. Anyone else? Oh and thanks for the work arounds. :)

以上就是MKMapView span doubling bug的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » HTML5 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏