Ios: mapkit, how to enable the curent location button on a map?

I am developing an application that shows a map. I have included the current location of the user in the map properties and now shows a Blue dot indicating the current location of the user, but now I want to enable the button at the bottom left to the Pic (Snap-shot of the Maps application on the iPhone).

Please tell me how can I get this on the map

enter image description here

+7
ios objective-c iphone ipad mapkit
source share
3 answers

Here you can find an implementation of this

iOS6MapsUserHeadingButton

Below is the code and you can find the images in the link above

//User Heading Button states images UIImage *buttonImage = [UIImage imageNamed:@"greyButtonHighlight.png"]; UIImage *buttonImageHighlight = [UIImage imageNamed:@"greyButton.png"]; UIImage *buttonArrow = [UIImage imageNamed:@"LocationGrey.png"]; //Configure the button userHeadingBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [userHeadingBtn addTarget:self action:@selector(startShowingUserHeading:) forControlEvents:UIControlEventTouchUpInside]; //Add state images [userHeadingBtn setBackgroundImage:buttonImage forState:UIControlStateNormal]; [userHeadingBtn setBackgroundImage:buttonImage forState:UIControlStateNormal]; [userHeadingBtn setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted]; [userHeadingBtn setImage:buttonArrow forState:UIControlStateNormal]; //Button shadow userHeadingBtn.frame = CGRectMake(5,425,39,30); userHeadingBtn.layer.cornerRadius = 8.0f; userHeadingBtn.layer.masksToBounds = NO; userHeadingBtn.layer.shadowColor = [UIColor blackColor].CGColor; userHeadingBtn.layer.shadowOpacity = 0.8; userHeadingBtn.layer.shadowRadius = 1; userHeadingBtn.layer.shadowOffset = CGSizeMake(0, 1.0f); [self.mapView addSubview:userHeadingBtn]; 
+2
source share
 MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView]; [trackButton setTarget:self]; [trackButton setAction:@selector(track:)]; [toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES]; 
+2
source share

You need to create MKUserTrackingBarButtonItem and pass it to MKMapview wherever you defined mapview. Something like below:

  - (void)viewDidLoad { [super viewDidLoad]; MKUserTrackingBarButtonItem *buttonItem = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.map]; self.navigationItem.rightBarButtonItem = buttonItem; } 
+1
source share

All Articles