Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios: mapkit how to enable curent location button on map?

I am developing application which is showing map. I enabled User current location in map properties and its now showing Blue dot indicating user's current location but now I want to enable Button in Bottom Left of below Pic (Snap shot of Maps application in iPhone).

Please tell me that how do I get this on Map

enter image description here

like image 570
Azhar Avatar asked Feb 10 '14 13:02

Azhar


People also ask

What is MAP kit in iOS?

MapKit is a powerful API available on iOS devices that makes it easy to display maps, mark locations, enhance with custom data and even draw routes or other shapes on top.


2 Answers

MKUserTrackingBarButtonItem *trackButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:mapView];   
[trackButton setTarget:self];
[trackButton setAction:@selector(track:)];

[toolbar setItems:[NSArray arrayWithObjects:trackButton, nil] animated:YES];
like image 73
Pawan Rai Avatar answered Sep 27 '22 23:09

Pawan Rai


Here you can find the implementation of this

iOS6MapsUserHeadingButton

Following is the code and you can find the images in the above given link

//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];
like image 34
Azhar Avatar answered Sep 27 '22 21:09

Azhar