Unable to force UIMapView to "increase" / setRegion: when the map loads for the first time

I have a UIViewController that loads a map with an existing bunch of pins. There are no problems with the appearance of contacts, but I can not get MKMapView to execute setRegion when the user first reaches mapView. I tried putting the code in any possible method that could work, viewDidLoad , viewWillLoad , mapViewWillStartLoadingMap , mapViewDidFinishLoadingMap , etc., to no avail.

And yet it will β€œzoom in” to the specified area if I go back to the previous viewController and then again enter the viewContoller containing the mapView.

Is there a secret way to do this that I don't know about? Do not call [mapView setRegion:(...) animated:YES]; to get a map for "zoom" / update to display the selected area.

Also, if anyone knows how to get the pins (I use MKPointAnnotation for mine) to animate, and also get a map for the zoom animation (neither do they, although I set both to animate ....), I was I would be grateful for this information.

Thanks!

Code:

 @implementation FindOnMapMapView @synthesize mapView; @synthesize mapViewTabBarItem; @synthesize results; @synthesize reverseGeocoder; - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake([defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]), MKCoordinateSpanMake(0.744494189288569, 0.744494189288569)); mapView.region = mapRegion; [mapView setRegion:mapRegion animated:YES]; NSMutableArray *annotations = [[NSMutableArray alloc] init]; for(ThePlace *place in results) { MKPointAnnotation *addAnnotation = [[MKPointAnnotation alloc] init]; [addAnnotation setCoordinate:CLLocationCoordinate2DMake(place.latitude, place.longitude)]; addAnnotation.title = place.placename; addAnnotation.subtitle = [NSString stringWithFormat:@"Distance: %@", place.distance]; [mapView addAnnotation:addAnnotation]; } [self.mapView addAnnotations:annotations ]; } - (void)viewWillAppear:(BOOL)animated { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; MKCoordinateRegion mapRegion = MKCoordinateRegionMake(CLLocationCoordinate2DMake([defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]), MKCoordinateSpanMake(0.744494189288569, 0.744494189288569)); NSLog(@"Region Coords are: Latitude:%f, Longitude:%f", [defaults doubleForKey:@"latitude"], [defaults doubleForKey:@"longitude"]); mapView.region = mapRegion; [mapView setRegion:mapRegion animated:YES]; } 
+4
source share
1 answer

Do you get it?

 - (void) viewDidAppear:(BOOL)animated { MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(firstPoint.coordinate, 2000, 2000); [mapView setRegion:region animated:YES]; } 

works for me

0
source

Source: https://habr.com/ru/post/1441358/


All Articles