So I have set my app to search for the user’s location upon pressing on a button.
-(IBAction)getLocation {
mapview.showsUserLocation = YES;}
Then I have set a Map Annotation as well to a certain location upon loading of the map view using this
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view.
[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 123;
region.center.longitude = 123;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapview setRegion:region animated:YES];
NewClass *ann = [[NewClass alloc] init];
ann.title = @"Place to go to";
ann.subtitle = @"subtitle";
ann.coordinate = region.center;
[mapview addAnnotation:ann];
}
Is it possible to be able to put a “Directions to Here” button to my annotation using MapKit? Any help would be awesome! Thanks!
To add the callout accessory, you have to follow the instruction from Anna Karenina.
To draw the route itself, you have to first obtain the route, there are plenty of excellent APIs that will give you the route between two given points, even allowing you to set params like if the kind of routes you want to include. Google Directions API is pretty impressive on that regard. You should check it.
Then you have to draw the route itself with
MKPolyline. You can check a toy app i put together a few months ago to show how to do this.