Am mai multe adnotări Vreau să adaug la MKMapView mea (poate 0-n elemente, unde n este, în general, în jurul valorii de 5). Pot adăuga adnotările bine, dar vreau să redimensiona harta pentru a se potrivi cu toate notațiile de pe ecran dintr-o dată, și eu nu sunt sigur cum să facă acest lucru.
M - am uitat la , -regionThatFits:dar nu sunt destul de sigur ce să facă cu ea. Voi posta un cod pentru a arăta ceea ce am până acum. Cred că acest lucru ar trebui să fie o sarcină în general simplă , dar mă simt un pic copleșit cu MapKit până în prezent.
- (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];
}
Observați, acest lucru se întâmplă tot ca am primit o actualizare de locație ... Nu știu dacă asta e un loc potrivit pentru a face acest lucru. Dacă nu, în cazul în care ar fi un loc mai bun? -viewDidLoad?
Mulțumesc anticipat.













