MKMapView在iOS 5下返回一个无效区域 - 纬度+纬度德尔塔/ 2超过100且不应超过90.
有没有人见过这个问题?
重现步骤:
预期结果: 在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。
答案 0 :(得分:1)
这似乎是一个充分的解决方法。而不是读取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相匹配功能并将值保持在地图的合法范围内,它适用于我。
答案 1 :(得分:0)
通过使用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.
希望这会有所帮助.. :)