I'm really confused about this issue. I have recently been having issues with my mapview tab in my application. Even to the point of starting over again. I'm just wondering if I am the only one having this issue or am I doing something wrong here.
I am fairly new to iOS but I know how to define a mapview's center and span in order to center on the user's location.
I've built this in its own view and it seems to work but when I put it in a tab controller...I have an issue. The map stays zoomed out while showing the user's location. It's supposed to show the user's location zoomed in.
My MapViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.mapView.delegate self];
[self.mapView setShowsUserLocation:YES];
// Do any additional setup after loading the view from its nib.
}
-(void)mapView:(MKMapView *)mapView
didUpdateUserLocation:(MKUserLocation *)userLocation
{
CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 500, 500);
[self.mapView setRegion:region animated:YES];
}
I also thought it could have something to do with the way I created the tab controller in the delegate.
My app delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[NWSWelcomeViewController alloc] initWithNibName:@"NWSWelcomeViewController" bundle:nil];
UIViewController *viewController2 = [[NWSMapViewViewController alloc] initWithNibName:@"NWSMapViewViewController" bundle:nil];
// UIViewController *viewController3 = [[NWSSettingsViewController alloc] initWithNibName:@"NWSSettingsViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2, /* viewController3 */];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
I am writing for iOS 5.1 and I am using the latest Xcode.
Yes, I have the settings for zooming enabled on the mapView.
I just want to get the user location to zoom in the mapview to the user's location.
This line in viewDidLoad:
[self.mapView.delegate self];
does nothing (it is trying to send the message self to self.mapView.delegate).
It doesn't actually set the map view's delegate and so the didUpdateUserLocation never gets called.
What you probably meant was:
[self.mapView setDelegate:self];
or this:
self.mapView.delegate = self;
This type of problems can be solved by storyboard also.
Go to the storyboard->controller->mapView
right click on the mapView a popover will show having a point delegate drag the delegate + point to controller![right click on map view![][1]](https://i.sstatic.net/dzajB.png)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With