缩放以适合所有注释的区域 - 最终在注释之间放大 [英] Zoom to fit region for all annotations - ending up zooming in between annotations

查看:160
本文介绍了缩放以适合所有注释的区域 - 最终在注释之间放大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将所有注释都安装到屏幕上有问题...有时会显示所有注释,但有时候应用会在两个注释之间放大,以便它们都不可见...
我希望应用程序始终使区域符合注释,而不是放大它们之间......我做错了什么?

I have a problem with fitting all my annotations to the screen... sometimes it shows all annotations, but some other times the app is zooming in between the two annotations so that none of them are visible... I want the app to always fit the region to the annotations and not to zoom in between them... what do I do wrong?

if ([mapView.annotations count] == 2) { 
 CLLocationCoordinate2D SouthWest = location;
 CLLocationCoordinate2D NorthEast = savedPosition;

 NorthEast.latitude = MAX(NorthEast.latitude, savedPosition.latitude);
 NorthEast.longitude = MAX(NorthEast.longitude, savedPosition.longitude); 

 SouthWest.latitude = MIN(SouthWest.latitude, location.latitude);
 SouthWest.longitude = MIN(SouthWest.longitude, location.longitude);

 CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:SouthWest.latitude longitude:SouthWest.longitude];
 CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:NorthEast.latitude longitude:NorthEast.longitude];

 CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast];

 MKCoordinateRegion region;
 region.span.latitudeDelta = meter / 111319.5;
 region.span.longitudeDelta = 0.0;
 region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0;
 region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0;

 region = [mapView regionThatFits:region];
 [mapView setRegion:region animated:YES];

 [locSouthWest release];
 [locNorthEast release]; 
}

任何想法?

谢谢!

推荐答案

而不是:

region.span.latitudeDelta = meter / 111319.5;
 region.span.longitudeDelta = 0.0;
 region.center.latitude = (SouthWest.latitude + NorthEast.latitude) / 2.0;
 region.center.longitude = (SouthWest.longitude + NorthEast.longitude) / 2.0;

尝试添加:

region.span.latitudeDelta = fabs(NorthEast.latitude - SouthWest.latitude) * 1.2; 
region.span.longitudeDelta = fabs(SouthWest.longitude - NorthEast.longitude) * 1.2; 
region.center.latitude = NorthEast.latitude - (NorthEast.latitude - SouthWest.latitude) * 0.5;
region.center.longitude = NorthEast.longitude + (SouthWest.longitude - NorthEast.longitude) * 0.5;

并删除:

CLLocationDistance meter = [locSouthWest distanceFromLocation:locNorthEast];

这篇关于缩放以适合所有注释的区域 - 最终在注释之间放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆