首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义注释详图索引视图未正确显示

自定义注释详图索引视图未正确显示
EN

Stack Overflow用户
提问于 2013-03-13 17:59:15
回答 1查看 137关注 0票数 1

我的应用程序中有一个自定义批注标注视图。我希望mapview自动调整,以便批注标注视图始终显示在visible area.right中。现在它的显示方式如image.any solution中所示吗?

EN

回答 1

Stack Overflow用户

发布于 2013-03-13 18:57:50

This is my answer for create Annotation.

调用下面的方法,以便在mapview中正确显示所有注释。(此方法在create annotation之后调用)

代码语言:javascript
复制
[self zoomToFitMapAnnotations:self.mapView];

上述方法的代码

代码语言:javascript
复制
-(void)zoomToFitMapAnnotations:(MKMapView*)mapView
{
    if([mapView.annotations count] == 0)
        return;

    CLLocationCoordinate2D topLeftCoord;
    topLeftCoord.latitude = -90;
    topLeftCoord.longitude = 180;

    CLLocationCoordinate2D bottomRightCoord;
    bottomRightCoord.latitude = 90;
    bottomRightCoord.longitude = -180;

    for(DDAnnotation* annotation in mapView.annotations)
    {
        topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
        topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

        bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
        bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);

    }

    NSLog(@"A%f, B%f, C%f, D%f,", topLeftCoord.latitude, topLeftCoord.longitude, bottomRightCoord.latitude, bottomRightCoord.longitude);

    MKCoordinateRegion region;
    region.center.latitude = topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5;
    region.center.longitude = topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5;
    region.span.latitudeDelta = fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.1;
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1;

    region = [mapView regionThatFits:region];
    [mapView setRegion:region animated:YES];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15382023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档