iphone - 在 iOS 中获取注释标注的位置

标签 iphone ios mapkit mkannotation mkannotationview

情况是这样的:我正在使用 MapKit 在 map 上显示多个位置。我有代码来计算允许 map 上所有点适合窗口的边界。我最近刚刚添加了代码以允许最近位置的标注气泡(正确的术语?)出现。不幸的是,标注气泡不适合窗口的边界。理想情况下,我希望调整缩放以适合所有注释以及最近位置的标注气泡。关于如何执行此操作的任何建议?这是我的缩放方法:

-(void)zoomToFitMapAnnotations:(MKMapView*)mv
{   
    if([mv.annotations count] == 0)
            return;

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

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

    for(WaybackAnnotation *annotation in [mv annotations])
    {
        if ([annotation isKindOfClass:[WaybackAnnotation class]])
        {
            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);
        }
    }

    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; // Add a little extra space on the sides
    region.span.longitudeDelta = fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.1; // Add a little extra space on the sides

    region = [mv regionThatFits:region];
    [mv setRegion:region animated:YES];
}

提前致谢! 詹姆斯

最佳答案

由于气泡始终显示在图钉上方,因此您需要在顶部添加一些额外的填充。您知道以屏幕像素为单位的填充高度。使用 MKMapView 的转换方法(-convertRect:toRegionFromView: 和 friend )将它们转换为地理坐标。

关于iphone - 在 iOS 中获取注释标注的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5159265/

相关文章:

iphone - Three20 照片滚动替代品?

ios - 在 map View 上显示 CLRegion

ios - 使用标题转动用户位置注释

ios - 从 iOS 应用程序打开 Twitter 无法正常工作

php - iPhone 上通过 PHP 和 HTTPS 进行数据库连接

iphone - 在静音模式下未调用 AudioServicesAddSystemSoundCompletion 回调

ios - 如何使用命令行在通过 USB 连接的手机上检查 iOS 应用程序的捆绑版本?

ios - 如何将自定义参数传递给 SKView 委托(delegate)方法 view(nodeFor)

iphone - 语义问题 : Incompatible pointer warning

xcode - 如何快速清除 map View 上的图钉?