Megvan több kommentárok szeretnék add a MKMapView (éppen 0-n elem, ahol n értéke általában körülbelül 5). Tudok hozzá a kommentárok finom, de azt szeretné méretezni a térképet, hogy illeszkedjen minden kommentárok képernyőn egyszerre, és nem vagyok biztos abban, hogyan kell ezt csinálni.
Már néztem -regionThatFits:, de nem vagyok egészen biztos abban, hogy mit kell csinálni vele. Írok egy kódot, hogy megmutasd, mit kaptam eddig. Azt hiszem, ez egy általában egyértelmű feladat, de érzem, egy kicsit túlterheltek MapKit eddig.
- (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];
}
Közlemény Ez minden történik, mint kapok helyfrissítést ... én nem tudom, hogy ez a megfelelő hely erre. Ha nem, akkor hol lenne jobb helye? -viewDidLoad?
Előre is köszönöm.













