MKMapView 完全缩小时的缩放问题

发布于 2024-12-17 17:15:11 字数 1087 浏览 0 评论 0原文

我通过单击按钮缩小地图。

因此,当地图完全缩小时,如果我尝试再次缩小它,那么它在设置区域时会崩溃。

不确定,但是有什么方法可以检测地图是否达到最大缩放限制吗?

这是我缩小地图的代码

-(void)setZoomLevelForNoPicksCurrentLocationAt:(CLLocationCoordinate2D)currentCoordinate{
 MKCoordinateSpan span;
 MKCoordinateRegion region;
 region.center = currentCoordinate;
 span.latitudeDelta =self.mapView.region.span.latitudeDelta *2;
 span.longitudeDelta =self.mapView.region.span.longitudeDelta *2;
 region.span = span;
 [self.mapView setRegion:region animated:YES];  
 [self.mapView regionThatFits:region];
}

任何类型的帮助将不胜感激。

请查找崩溃日志

<块引用>

* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无效区域中心:+38.82259098,-67.50000000跨度:+307.41536753,+450.00000000” * 第一次抛出时调用堆栈: ( 0 核心基础 0x013c8be9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x0151d5c2 objc_异常_抛出 + 47 2 CoreFoundation 0x013c8b21 -[NSException 引发] + 17 3 XXXapp 0x000ab237 -[MapViewController setZoomLevelForNoPicksCurrentLocationAt:] + 312

I am zooming out the map on the click of the button.

So when the map is fully zoomed out and if I try to again zoom out it then it crashes while setting the region.

Not sure but, Is there any way out to detect if the map has reached it maximum zoom limit?

Here is my code to zoom out the map

-(void)setZoomLevelForNoPicksCurrentLocationAt:(CLLocationCoordinate2D)currentCoordinate{
 MKCoordinateSpan span;
 MKCoordinateRegion region;
 region.center = currentCoordinate;
 span.latitudeDelta =self.mapView.region.span.latitudeDelta *2;
 span.longitudeDelta =self.mapView.region.span.longitudeDelta *2;
 region.span = span;
 [self.mapView setRegion:region animated:YES];  
 [self.mapView regionThatFits:region];
}

Any kind of help will be really appreciated.

Please find the crash log

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region center:+38.82259098, -67.50000000 span:+307.41536753, +450.00000000'
*
Call stack at first throw:
(
0 CoreFoundation 0x013c8be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0151d5c2 objc_exception_throw + 47
2 CoreFoundation 0x013c8b21 -[NSException raise] + 17
3 XXXapp 0x000ab237 -[MapViewController setZoomLevelForNoPicksCurrentLocationAt:] + 312

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮生未歇 2024-12-24 17:15:11

u 可以提供的最小跨度值为 0.0 。在运行时,跨度的值变为负值,这会导致崩溃。只需硬线并尝试放置 nslog 来监视跨度的值。最大跨度值为 180.0,高于该值将导致崩溃。

The minimum span value u can provide is 0.0 . At run-time the value of span is getting negative which causes the crash. Just hard cord and try and put a nslog to monitor the value of span. The maximum span value is 180.0 above that will result in crash.

℉服软 2024-12-24 17:15:11

我刚刚在增量计算中添加了以下检查,以防止应用区域崩溃:

//calculate deltas
double deltaLat = fabs(max_lat - min_lat) * 2;
if (deltaLat > 180) deltaLat = 180;

double deltaLong = fabs(max_long - min_long) * 2;
if (deltaLong>360) deltaLong = 360;

因此区域增量纬度不能超过 180,经度不能超过 360。

I just added following checks to deltas calculation that prevent crashes on applying region:

//calculate deltas
double deltaLat = fabs(max_lat - min_lat) * 2;
if (deltaLat > 180) deltaLat = 180;

double deltaLong = fabs(max_long - min_long) * 2;
if (deltaLong>360) deltaLong = 360;

So the region delta latitude can not be more then 180 and longitude more then 360.

梦萦几度 2024-12-24 17:15:11

经过几次尝试和错误测试后,Swift 3.0 中的解决方案。

以下是我计算增量的方法:

let distanceLat = min(abs((currentLatitude! - pinLatitude) * 5), 180)
let distanceLon = min(abs((currentLongitude! - pinLongitude) * 5), 180)

*5 是任意的,请随意更改它。

Solution in Swift 3.0 after a few trial and error tests.

Here is how I calculated my deltas:

let distanceLat = min(abs((currentLatitude! - pinLatitude) * 5), 180)
let distanceLon = min(abs((currentLongitude! - pinLongitude) * 5), 180)

The *5 is arbitrary, feel free to change it as you will.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文