1

I have a mapViewController (in a Navigation Controller). When I open it for the first time, after viewDidLoad, - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation gets called.

When I go back to the previous viewController and come again to the mapViewController, the didUpdateUserLocation delegate is not being called, hence my annotations are not getting shown.

Please help me in finding the solution to the problem. Thank you.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Hyder
  • 1,163
  • 2
  • 13
  • 37
  • Where are you setting your delegate? Have you confirmed that your delegate is being properly set? – iwasrobbed Jun 07 '13 at 20:15
  • @iWasRobbed: in viewDidLoad I am setting my delegate like this `self.mapView.delegate = self;` Is there anything wrong? – Hyder Jun 07 '13 at 20:16
  • If you're also setting the delegate in a different view controller, the `viewDidLoad` method might not be called again if you immediately come back to a view that you just dismissed. Try setting it in the `viewWillAppear` method instead – iwasrobbed Jun 07 '13 at 20:17
  • @iWasRobbed: Tried what you said, but still the didUpdateUserLocation not being called when coming back to mapView. In fact I noticed that my viewWillAppear is not even getting called once. – Hyder Jun 07 '13 at 20:21

2 Answers2

0

If you want the map view to continue to track the user’s location and update it periodically, you should set MapView showsUserLocation to YES (the default value is NO).

Try

- (void)viewWillAppear:(BOOL)animated 
{    
    [super viewWillAppear:animated];
    ...
    [mapView setShowsUserLocation: YES];
}

- (void)viewWillDisappear:(BOOL)animated 
{
    [super viewWillDisappear:animated];
    ...
    [mapView setShowsUserLocation: NO];
}

Apple Doc: http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html

HepaKKes
  • 1,555
  • 13
  • 22
  • regarding your problem with the `viewWillAppear`, [link](http://stackoverflow.com/questions/131062/iphone-viewwillappear-not-firing) – HepaKKes Jun 07 '13 at 21:58
-1

Call this method in - view will appear method of same class

[locationManager startUpdatingLocation];
Hitesh
  • 21
  • 3