Ho parecchie annotazioni voglio aggiungere al mio MKMapView (che poteva articoli 0-n, dove n è in genere intorno al 5). Posso aggiungere le annotazioni bene, ma voglio ridimensionare la mappa per adattarsi a tutte le annotazioni sullo schermo in una sola volta, e non sono sicuro come fare questo.
Sono stato a guardare -regionThatFits:, ma io non sono molto sicuro di cosa fare con esso. Vi posto il codice per mostrare quello che ho finora. Penso che questo dovrebbe essere un compito di solito, semplice, ma mi sento un po 'sopraffatto con MapKit finora.
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
location = newLocation.coordinate;
//One location is obtained.. just zoom to that location
MKCoordinateRegion region;
region.center = location;
//Set Zoom level using Span
MKCoordinateSpan span;
span.latitudeDelta = 0.015;
span.longitudeDelta = 0.015;
region.span = span;
// Set the region here... but I want this to be a dynamic size
// Obviously this should be set after I've added my annotations
[mapView setRegion:region animated:YES];
// Test data, using these as annotations for now
NSArray *arr = [NSArray arrayWithObjects:@one, @two, @three, @four, nil];
float ex = 0.01;
for (NSString *s in arr) {
JBAnnotation *placemark = [[JBAnnotation alloc] initWithLat:(location.latitude + ex) lon:location.longitude];
[mapView addAnnotation:placemark];
ex = ex + 0.005;
}
// What do I do here?
[mapView setRegion:[mapView regionThatFits:region] animated:YES];
}
Notate, tutto questo avviene come ricevo un aggiornamento di posizione ... non so se questo è un posto adatto per fare questo. In caso contrario, dove sarebbe un posto migliore? -viewDidLoad?
Grazie in anticipo.













