If you want to start with showing one region and then zoom in, you have to issue two or more setRegion
calls because setRegion
by itself doesn't let you control the starting region or the speed of the animation.
In viewDidLoad
, set the initial region's span
so the entire UK is visible (try deltas of 10.0
instead of 0.15
). You could also set animated
to NO
for the initial region.
Then before the end of viewDidLoad
, schedule the zoom-in to be executed a few seconds later:
- (void)viewDidLoad
{
...
[self performSelector:@selector(zoomInToMyLocation)
withObject:nil
afterDelay:5]; //will zoom in after 5 seconds
}
The zoomInToMyLocation
method might look like this:
-(void)zoomInToMyLocation
{
MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = 51.502729 ;
region.center.longitude = -0.071948;
region.span.longitudeDelta = 0.15f;
region.span.latitudeDelta = 0.15f;
[mapView setRegion:region animated:YES];
}
One thing you might have to take care of when using performSelector
is to cancel a pending call if the view is closed or deallocated before the call is scheduled to run. For example, if the user closes the view two seconds after loading it. Three seconds later, the scheduled method may still get called but will crash since the view is gone. To avoid this, cancel any pending performs in viewWillDisappear:
or wherever appropriate:
[NSObject cancelPreviousPerformRequestsWithTarget:self];