Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

iphone - Zoom in a MKMapView programmatically

I'm using a MKMapView inside an iPhone app. When I click a button the zoom level must increase. This is my first approach:

MKCoordinateRegion zoomIn = mapView.region;
zoomIn.span.latitudeDelta *= 0.5;
[mapView setRegion:zoomIn animated:YES];

However, this code had no effect, since I didn't update the longitudeDelta value. So I added this line:

zoomIn.span.longitudeDelta *= 0.5;

Now it works, but only sometimes. The latitudeDelta and longitudeDelta don't change in the same way, I mean, their values are not proportional. Any idea how to solve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have no idea if this is the right way to do it, but I'm using this to zoom in and out.

        case 0: { // Zoom In
        //NSLog(@"Zoom - IN");
        MKCoordinateRegion region;
        //Set Zoom level using Span
        MKCoordinateSpan span;  
        region.center=mapView.region.center;

        span.latitudeDelta=mapView.region.span.latitudeDelta /2.0002;
        span.longitudeDelta=mapView.region.span.longitudeDelta /2.0002;
        region.span=span;
        [mapView setRegion:region animated:TRUE];
    }
        break;

    // Zoom Out 
    case 2: {
        //NSLog(@"Zoom - OUT");
        MKCoordinateRegion region;
        //Set Zoom level using Span
        MKCoordinateSpan span;  
        region.center=mapView.region.center;
        span.latitudeDelta=mapView.region.span.latitudeDelta *2;
        span.longitudeDelta=mapView.region.span.longitudeDelta *2;
        region.span=span;
        [mapView setRegion:region animated:TRUE];
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...