How to set-up zoom level in iOS?

1k views Asked by At

I am using the code given below to set a region in map view:

    CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];

    CLLocationDistance visibleDistance = 100000;
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, visibleDistance, visibleDistance);
    MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:region];

    [self.mapView setRegion:adjustedRegion animated:YES];
    [self.mapView setCenterCoordinate:loc];
    [self.mapView setZoomEnabled:YES];

It shows the entire map in a small area. How can increment the zoom level?

4

There are 4 answers

0
AudioBubble On

Try this,

CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, visibleDistance, visibleDistance);
region.span.latitudeDelta = 0.15f;     
region.span.longitudeDelta = 0.15f; 
[self.mapView setRegion:region animated:YES];
[self.mapView setZoomEnabled:YES];
1
matt On

Change the visibleDistance to a smaller number. Experiment until you find something you like.

3
Mehul Patel On

You can also take a help of span value for MapView. Animate to that small area and span map to zoom for required value.

Use below code:

CLLocationCoordinate2D loc = (CLLocationCoordinate2D )[self geoCodeUsingAddress:searchBar.text];

[UIView animateWithDuration:1.5 animations:^{

    MKCoordinateRegion region;
    region.center.latitude = loc.latitude;
    region.center.longitude = loc.longitude;
    region.span.latitudeDelta = 0.15f;       // Decrement value to zoom
    region.span.longitudeDelta = 0.15f;      // Decrement value to zoom

    [self.mapView setRegion:region animated:YES];

} completion:^(BOOL finished) { }];
0
Neenu On

Finally I have solved the issue by removing

[self.mapView setCenterCoordinate:loc];

I worked well when i removed the above.