The region
is a MKCoordinateRegion
. So the first line initializes a local variable with the structure (using the old C89 convention):
MKCoordinateRegion region = {{0.0, 0.0}, {0.0, 0.0}};
and the subsequent lines just update that previously initialized structure with the desired values:
region.center.latitude = latitude;
region.center.longitude = longitude;
region.span.latitudeDelta = 0.1f;
For what it is worth, you could alternatively just instantiate it and set the values all in one step (again, using the C89 convention):
MKCoordinateRegion region = { { latitude, longitude }, { 0.1, 0.1 } };
Or, nowadays, one might use the C99 convention of designated initializers:
MKCoordinateRegion region = {
.center = { .latitude = latitude, .longitude = longitude },
.span = { .latitudeDelta = 0.1, .longitudeDelta = 0.1 }
};
Again, this initializes and populates the MKCoordinateRegion
in one step (and in this case, in a less cryptic manner than the C89 pattern).
The alternative is to build CLLocationCoordinate2D
, MKCoordinateSpan
, and MKCoordinateRegion
using the various xxxMake
functions:
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
MKCoordinateSpan span = MKCoordinateSpanMake(0.1, 0.1);
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
For more information about initializing C structs, I would refer you to How to initialize a struct in accordance with C programming language standards. Also, the GCC documentation talks about designated initializers, including structs.
Or, if you are trying to set a map view’s region, another approach is to use MKMapCamera
instead:
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(latitude, longitude);
MKMapCamera *camera = [MKMapCamera cameraLookingAtCenterCoordinate:center fromDistance:1000 pitch:0 heading:0];
[self.mapView setCamera:camera animated:true];
But, bottom line, the region
is effectively the range of latitude and longitude coordinates that the map will show (as defined by the combination of the center
, where the map is looking, and the span
, how much of the map is visible).
All of these map coordinates and spans should not be confused with the frame
of the map view, which is the visual size of the map view that will show that region.