[英]Invalid MKMapView region in iOS 5
MKMapView returns an invalid region under iOS 5 -- latitude + latitudeDelta/2 is over 100 and shouldn't be over 90. MKMapView在iOS 5下返回无效区域-latitude + latitudeDelta / 2超过100,并且不应超过90。
Has anyone seen this problem? 有没有人看过这个问题?
Steps to Reproduce: 重现步骤:
Expected Results: In iOS 4, the mapView.region is reasonable: 预期结果:在iOS 4中,mapView.region是合理的:
lat=2.202047 lon=-67.500000 latDelta=165.698164 lonDelta=225.000000
In iOS 5, however, the mapView.region is out of bounds: 但是,在iOS 5中,mapView.region超出范围:
lat=17.978733 lon=-67.500000 latDelta=165.698164 lonDelta=225.000000
Latitudes should be within the -90 to 90 range. 纬度应在-90至90范围内。 However, in iOS 5, lat + latDelta/2 is 100.827815. 但是,在iOS 5中,lat + latDelta / 2为100.827815。 That is not possible. 这是不可能的。 While I can clamp the values at +/- 90, the offset difference is causing problems with our overlays. 虽然我可以将值钳位在+/- 90,但偏移量差异导致覆盖层出现问题。
Regression: Does not happen in iOS 4.3. 回归:在iOS 4.3中不会发生。 Happens regularly in iOS 5. Screen dumps of the map views look identical even though the center latitude is 15 degrees off. 在iOS 5中会定期发生。即使中心纬度偏离15度,地图视图的屏幕转储看起来也一样。
Notes: Project file and screen dumps can be downloaded here . 注意:项目文件和屏幕转储可以在此处下载。
This seems to be an adequate workaround. 这似乎是一个适当的解决方法。 Rather than reading the mapView.region property, call this method instead: 而不是读取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
Now one could argue (correctly!) that this code isn't 100% correct either because the center value of a Mercator projection in lon/lat isn't really halfway between the top and bottom, but since this matches iOS 4 functionality and keeps the values within the legal range for the map, it works for me. 现在,人们可能会争辩(正确!)此代码也不是100%正确的,因为lon / lat中的Mercator投影的中心值实际上不在顶部和底部之间,而是因为它与iOS 4功能匹配并保持地图合法范围内的值,它对我有用。
By using the MKMapView+ZoomLevel category, you won't have to bother setting the region at all. 通过使用MKMapView + ZoomLevel类别,您完全不必费心设置区域。
here is very good tutorial on the same 这是同一个很好的教程
http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/ http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
or 要么
http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/ http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/
After you perform the zoom/pinch operation try to load the region in 执行缩放/收缩操作后,尝试将区域加载到
-(void) mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
instead in 代替在
regionDidChangeAnimated.
hope this will help..:) 希望这会有所帮助..::)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.