Reputation: 3196
I use this code in viewWillLayoutSubviews to set the initial region of my map.
CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(13.747266, 100.526804);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 800, 800)];
[self.mapView setRegion:adjustedRegion animated:YES];
NSLog(@"%f",adjustedRegion.span.latitudeDelta);
However, the initial zoom level doesn't work. The coordinate is correct, but it always zoom in to probably the max level. I check the span of the region and got 0.0. How do I fix this.
Upvotes: 14
Views: 21098
Reputation: 6887
Custom span setting:
region.span.longitudeDelta = 0.04;
region.span.latitudeDelta = 0.04;
else programmatically:
region.span.longitudeDelta = geoMapView.region.span.latitudeDelta;
region.span.latitudeDelta = geoMapView.region.span.latitudeDelta;
Upvotes: 1
Reputation: 17535
You need to set your span.So give your span value here.
adjustedRegion.span.longitudeDelta = 0.005;
adjustedRegion.span.latitudeDelta = 0.005;
Upvotes: 29