Current location button on ios MKMapView

Rakesh picture Rakesh · Nov 14, 2014 · Viewed 13.2k times · Source

I am using MKMapView in my iOS Application. I have search bar in my view. If I search for location on map, I am putting annotation on that searched location. Now the issue is, I want to go back to my current location. I have seen Google Maps application, they have one button on Map which will send the user to current location.

How to show that button?. And how to get click event of that button?.

Answer

Aleksey Mazurenko picture Aleksey Mazurenko · Jun 24, 2016
- (void)viewDidLoad
{
    [super viewDidLoad];    
    MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map];
    self.navigationItem.rightBarButtonItem = buttonItem;
}