Setting the zoom level in MapKit Xcode

How to set the zoom level of my MapKit in the SDK? For example, I live in New York, and I set 4 coordinate positions in my ProjectName-info.plist (URL Types> Element 0> URL Schemas> Item 0), then I set my code in my UIViewController subclass file:

#import "GoogleMap.h"
#import "MyAnnotation.h"

@implementation GoogleMap

        - (void)viewDidLoad {
        [super viewDidLoad];

        variable1 = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] 
                                                             pathForResource:@"NewYorkAreas" 
                                                             ofType:@"plist"]];

        double minLat = [[variable1 valueForKeyPath:@"@min.latitude"] doubleValue];
        double maxLat = [[variable1 valueForKeyPath:@"@max.latitude"] doubleValue];
        double minLon = [[variable1 valueForKeyPath:@"@min.longitude"] doubleValue];
        double maxLon = [[variable1 valueForKeyPath:@"@max.longitude"] doubleValue];

        MKCoordinateRegion region;
        region.center.latitude = (maxLat + minLat) / 2.0;
        region.center.longitude = (maxLon + minLon) / 2.0;
        region.span.latitudeDelta = (maxLat - minLat) * 1.05;
        region.span.longitudeDelta = (maxLon - minLon) * 1.05;
        map.region = region;

        for (NSDictionary *newYorkAreasDict in variable1){
            MyAnnotation *annotation = [[MyAnnotation alloc] initWithDictionary:newYorkAreasDict];
            [map addAnnotation:annotation];
            [annotation release];
        }
    }

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{

        if (map.userLocation == annotation){
            return nil;
        }

        NSString *identifier = @"MY_IDENTIFIER";

        MKAnnotationView *annotationView = [map dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil){
            annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 
                                                           reuseIdentifier:identifier] 
                              autorelease];
            annotationView.image = [UIImage imageNamed:@"logo.png"];
            annotationView.canShowCallout = YES;

            annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        }
        return annotationView;
    }

So, that’s all I have in my code, which works fine when I launch and debug the application, and shows me the location of all 4 areas that I set at a good zoom level, but now I only want 1 to install, so when I deleted another area 3 and when I start it and give only one area, the zoom level seems very close to the map:

enter image description here

, (, - ), , , " Google", Google : enter image description here

, , - , Google, !

( -, , - lol)

+3
1

latitudeDelta longitudeDelta. :

MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake((maxLat + minLat) / 2.0, (maxLon + minLon) / 2.0), 1000.0, 1000.0);
region.span.latitudeDelta = MAX(region.span.latitudeDelta, (maxLat - minLat) * 1.05);
region.span.longitudeDelta = MAX(region.span.longitudeDelta, (maxLon - minLon) * 1.05);

1 1 , , .

+3

All Articles