开发者

MKMapView reset back to world view

How do I reset an MKMapV开发者_开发问答iew back to the world view zoom level?


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];


Try this:

MKCoordinateRegion region = MKCoordinateRegionMake(mapView.centerCoordinate, MKCoordinateSpanMake(180, 360));
[mapView setRegion:region animated:YES]; 

This will set a new region for the map view using the current center coordinate, and the maximum possible span (180 degrees of latitude, 360 degrees of longitude).


For those hoping to do this in Swift:

let region = MKCoordinateRegion(.world)
mapView.setRegion(region, animated: true)


MKMapView can not zoom out to show the whole world. No matter what you are using, MKMapRectWorld, zoom level 0, or MKCoordinateSpanMake(180, 360).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜