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.
The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.
MKCoordinateRegion zoomIn = mapView. region; zoomIn. span. latitudeDelta *= 0.5; [mapView setRegion:zoomIn animated:YES];
Creates a coordinate span that represents a width and height on a map.
It takes a region object which has latitudeDelta and longitudeDelta . Use these to set the zoom level. Updated: in a Region object the latitude and longitude specify the center location and latitudeDelta and longitudeDelta specify the span of the viewable map area.
You need to set your span.So give your span value here.
adjustedRegion.span.longitudeDelta = 0.005;
adjustedRegion.span.latitudeDelta = 0.005;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With