相关疑难解决方法(0)

缩放MKMapView以适合注释引脚?

我正在使用MKMapView并在地图上添加了许多注释引脚,大约5-10公里的区域.当我运行应用程序时,我的地图开始缩小以显示整个世界,缩放地图以使引脚适​​合视图的最佳方法是什么?

编辑: 我最初的想法是使用MKCoordinateRegionMake并从我的注释中计算坐标中心,longitudeDelta和latitudeDelta.我很确定这会起作用,但我只是想检查一下我没有遗漏任何明显的东西.

代码添加,BTW:FGLocation是一个符合的类MKAnnotation,locationFake是NSMutableArray这些对象中的一个.欢迎评论....

- (MKCoordinateRegion)regionFromLocations {
    CLLocationCoordinate2D upper = [[locationFake objectAtIndex:0] coordinate];
    CLLocationCoordinate2D lower = [[locationFake objectAtIndex:0] coordinate];

    // FIND LIMITS
    for(FGLocation *eachLocation in locationFake) {
        if([eachLocation coordinate].latitude > upper.latitude) upper.latitude = [eachLocation coordinate].latitude;
        if([eachLocation coordinate].latitude < lower.latitude) lower.latitude = [eachLocation coordinate].latitude;
        if([eachLocation coordinate].longitude > upper.longitude) upper.longitude = [eachLocation coordinate].longitude;
        if([eachLocation coordinate].longitude < lower.longitude) lower.longitude = [eachLocation coordinate].longitude;
    }

    // FIND REGION
    MKCoordinateSpan locationSpan;
    locationSpan.latitudeDelta = upper.latitude - lower.latitude;
    locationSpan.longitudeDelta = upper.longitude - lower.longitude;
    CLLocationCoordinate2D …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c mkmapview ios

190
推荐指数
14
解决办法
10万
查看次数

标签 统计

cocoa-touch ×1

ios ×1

iphone ×1

mkmapview ×1

objective-c ×1