有没有办法让 mkmapview 放大以显示所有注释?

发布于 2024-10-29 17:49:58 字数 1334 浏览 0 评论 0原文

有没有办法让 mkmapview 放大以显示所有注释?我在北美有 94 个注释,我不希望用户必须缩小很多。这是我的代码片段:

- (void)viewDidLoad {
    [super viewDidLoad];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];




    // Central Alabama Chapter

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region.center.latitude = 33.45606;
    region.center.longitude = -86.83078;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;

    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];

    DisplayMap *ann = [[DisplayMap alloc] init]; 
    ann.title = @"Central Alabama Chapter";
    ann.subtitle = @"721 Hillmoor Lane Homewood, Alabama 35209"; 
    ann.coordinate = region.center; 
    [mapView addAnnotation:ann];


    // Walnut Ridge Fire Department

    MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region1.center.latitude = 36.11493;
    region1.center.longitude = -90.95695;
    region1.span.longitudeDelta = 0.01f;
    region1.span.latitudeDelta = 0.01f;



    DisplayMap *ann1 = [[DisplayMap alloc] init]; 
    ann1.title = @"Walnut Ridge Fire Department";
    ann1.subtitle = @"3217 Highway 67 # B, Walnut Ridge, AR"; 
    ann1.coordinate = region1.center; 
    [mapView addAnnotation:ann1];

Is there a way to have the mkmapview be zoomed in to show all the annotations? I have 94 annotations in North America and i don't want the user to have to zoom out a lot. Here is a snippet of my code:

- (void)viewDidLoad {
    [super viewDidLoad];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];




    // Central Alabama Chapter

    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region.center.latitude = 33.45606;
    region.center.longitude = -86.83078;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;

    [mapView setRegion:region animated:YES]; 

    [mapView setDelegate:self];

    DisplayMap *ann = [[DisplayMap alloc] init]; 
    ann.title = @"Central Alabama Chapter";
    ann.subtitle = @"721 Hillmoor Lane Homewood, Alabama 35209"; 
    ann.coordinate = region.center; 
    [mapView addAnnotation:ann];


    // Walnut Ridge Fire Department

    MKCoordinateRegion region1 = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
    region1.center.latitude = 36.11493;
    region1.center.longitude = -90.95695;
    region1.span.longitudeDelta = 0.01f;
    region1.span.latitudeDelta = 0.01f;



    DisplayMap *ann1 = [[DisplayMap alloc] init]; 
    ann1.title = @"Walnut Ridge Fire Department";
    ann1.subtitle = @"3217 Highway 67 # B, Walnut Ridge, AR"; 
    ann1.coordinate = region1.center; 
    [mapView addAnnotation:ann1];

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

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

发布评论

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

评论(1

居里长安 2024-11-05 17:49:58
double minLat=360.0f,minLon=360.0f;
double maxLat=-360.0f,maxLon=-360.0f;

for (<MKAnnotation> vu in [theMapView annotations]) {
    if ( vu.coordinate.latitude  < minLat ) minLat = vu.coordinate.latitude;
    if ( vu.coordinate.latitude  > maxLat ) maxLat = vu.coordinate.latitude;
    if ( vu.coordinate.longitude < minLon ) minLon = vu.coordinate.longitude;
    if ( vu.coordinate.longitude > maxLon ) maxLon = vu.coordinate.longitude;
}
CLLocation *newCenter = [[CLLocation alloc] initWithLatitude: (maxLat+minLat)/2.0
                                                   longitude: (maxLon+minLon)/2.0];
theMapView.region = MKCoordinateRegionMake (newCenter.coordinate,  
                        MKCoordinateSpanMake( fabs(maxLat-minLat), fabs(maxLon-minLon) ) );
double minLat=360.0f,minLon=360.0f;
double maxLat=-360.0f,maxLon=-360.0f;

for (<MKAnnotation> vu in [theMapView annotations]) {
    if ( vu.coordinate.latitude  < minLat ) minLat = vu.coordinate.latitude;
    if ( vu.coordinate.latitude  > maxLat ) maxLat = vu.coordinate.latitude;
    if ( vu.coordinate.longitude < minLon ) minLon = vu.coordinate.longitude;
    if ( vu.coordinate.longitude > maxLon ) maxLon = vu.coordinate.longitude;
}
CLLocation *newCenter = [[CLLocation alloc] initWithLatitude: (maxLat+minLat)/2.0
                                                   longitude: (maxLon+minLon)/2.0];
theMapView.region = MKCoordinateRegionMake (newCenter.coordinate,  
                        MKCoordinateSpanMake( fabs(maxLat-minLat), fabs(maxLon-minLon) ) );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文