Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKMapView reset back to world view

How do I reset an MKMapView back to the world view zoom level?

like image 754
TheLearner Avatar asked Jan 20 '11 15:01

TheLearner


2 Answers

For those hoping to do this in Swift:

let region = MKCoordinateRegion(.world)
mapView.setRegion(region, animated: true)
like image 175
CodeBender Avatar answered Nov 10 '22 00:11

CodeBender


The map rect for the world is stored as a constant named MKMapRectWorld.

MKCoordinateRegion worldRegion = MKCoordinateRegionForMapRect(MKMapRectWorld);
map.region = worldRegion;

One other way is to set the zoom level of the map. Although the MapKit framework does not support zoom levels as Google Maps API does, you can use this category extension written by Troy Brant.

Set the center coordinate to 0, 0 with zoom level 0 to get the same result.

[map setCenterCoordinate:CLLocationCoordinate2DMake(0, 0) zoomLevel:0 animated:0];
like image 31
Anurag Avatar answered Nov 10 '22 00:11

Anurag