0

I'm using the following code to make zoom out on map MKMapView .

float zoom=1.5;
MKCoordinateRegion region;
//Set Zoom level using Span
MKCoordinateSpan span;  
region.center=mapView.region.center;
span.latitudeDelta=mapView.region.span.latitudeDelta *zoom;
span.longitudeDelta=mapView.region.span.longitudeDelta *zoom;
region.span=span;
[mapView setRegion:region animated:TRUE];

But in the case when zoom=1.1, zoom=1.3, or zoom=1.5, the map displays the same regian in all 3 cases. This region looks the same as when zoom=2.

How can I make display the map so that the correct region is displayed in each of these cases?

yuji
  • 16,695
  • 4
  • 63
  • 64

2 Answers2

1

Try this one....

region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES]; 

You can set span.longitudeDeltaand span.latitudeDelta as how much u want to zoom-in or out... And also initialize MKCoordinateRegion..

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } } 

Set delegate to mapView

[mapView setDelegate:self];
Krunal
  • 1,318
  • 1
  • 13
  • 31
  • MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } } ; region.center=mapView.region.center; float f1=mapView.region.span.latitudeDelta; float f2=mapView.region.span.longitudeDelta; f1=f1*1.1; f2=f2*1.1; region.span.latitudeDelta=f1; region.span.longitudeDelta=f2; [ mapView setRegion:region animated:TRUE]; – Michael1230661 Feb 24 '12 at 12:34
  • do you mean that I need to write this code ? in this case will be the same situation so it doesn't help. In my case "self" is already the delegate of mapView. – Michael1230661 Feb 24 '12 at 12:35
1

Try this

MKCoordinateSpan span; 
//You can set span for how much Zoom to be display
span.latitudeDelta=.005;
span.longitudeDelta=.005;

//set Region to be display on MKMapView
MKCoordinateRegion cordinateRegion;
cordinateRegion.center=latAndLongLocation.coordinate;
//latAndLongLocation coordinates to be display 
cordinateRegion.span=span;

[mapView setRegion:cordinateRegion animated:YES];
//mapView MkMapView

It'll definitely work.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56