在IOS 5
问题描述:
的MKMapView下的iOS 5返回一个无效区域无效的MKMapView区域 - 纬度+ latitudeDelta/2超过100,不应该超过90在IOS 5
有没有人看到这个问题?
重现步骤:
- 创建的MKMapView
- 日志从regionDidChangeAnimated委托方法
- 缩小地图尽可能内mapView.region并将其拖动到右边,所以视图被滚动到顶部/左
预期结果: 在iOS系统4中,mapView.region合理:
lat=2.202047 lon=-67.500000 latDelta=165.698164 lonDelta=225.000000
在iOS 5中,然而,mapView.region超出范围:
lat=17.978733 lon=-67.500000 latDelta=165.698164 lonDelta=225.000000
纬度应该是-90到90范围内。但是,在iOS 5中,lat + latDelta/2是100.827815。这是不可能的。虽然我可以将值限制在+/- 90,但偏移差异会导致覆盖问题。
回归: 在iOS 4.3中不会发生。在iOS 5中定期发生。即使中心纬度为15度,地图视图的屏幕转储看起来也是相同的。
备注: 项目文件和屏幕转储可以下载here。
答
通过使用MKMapView + ZoomLevel类别,您根本不必麻烦设置区域。
这里是同一
http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
或
http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/
在执行变焦/缩放操作尝试加载该地区
-(void) mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
非常好的教程
代替
regionDidChangeAnimated.
希望这将有助于.. :)
答
这似乎是一个适当的解决办法。而不是读的mapView.region属性,调用此方法来代替:(!正确)
@implementation MKMapView(fixedRegion)
-(MKCoordinateRegion) fixedRegion_
{
// this call is broken on iOS 5, as is the region property, so don't use them
// return([self convertRect:self.bounds toRegionFromView:self]);
CLLocationCoordinate2D topLeft = [self convertPoint:CGPointZero toCoordinateFromView:self];
CLLocationCoordinate2D bottomRight = [self convertPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height) toCoordinateFromView:self];
MKCoordinateRegion region;
region.center.latitude = (topLeft.latitude + bottomRight.latitude)/2;
region.center.longitude = (topLeft.longitude + bottomRight.longitude)/2;
region.span.latitudeDelta = fabs(topLeft.latitude - bottomRight.latitude);
region.span.longitudeDelta = fabs(topLeft.longitude - bottomRight.longitude);
return region;
}
@end
现在,人们可以说,这个代码是不是100%正确是因为在LON一个墨卡托投影的中心值/ lat并不是真正在顶部和底部之间的一半,但是由于这与iOS 4的功能相匹配,并将值保存在地图的合法范围内,因此适用于我。
设置mapView区域不是问题。在用户通过捏放/缩放缩小视图后,我看到了无效区域。 – EricS
以及你可以限制地区..i.e用户只能缩小到一定的水平。 –
我已经更新了我的回答,请检查 –