Skip to content

Instantly share code, notes, and snippets.

@rbsgn
Created July 29, 2013 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbsgn/6107546 to your computer and use it in GitHub Desktop.
Save rbsgn/6107546 to your computer and use it in GitHub Desktop.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MKPlacemark *firstPlacemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(55.755768, 37.617671)
addressDictionary:nil];
MKPlacemark *secondPlacemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(55.910528, 37.736339)
addressDictionary:nil];
[self.mapView showAnnotations:@[ firstPlacemark, secondPlacemark ] animated:NO];
MKMapItem *firstMapItem = [[MKMapItem alloc] initWithPlacemark:firstPlacemark];
MKMapItem *secondMapItem = [[MKMapItem alloc] initWithPlacemark:secondPlacemark];
MKDirectionsRequest *routeRequest = [[MKDirectionsRequest alloc] init];
routeRequest.source = firstMapItem;
routeRequest.destination = secondMapItem;
MKDirections *directions = [[MKDirections alloc] initWithRequest:routeRequest];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
MKRoute *firstRoute = [response.routes firstObject];
[self.mapView addOverlay:firstRoute.polyline level:MKOverlayLevelAboveLabels];
}];
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay
{
MKOverlayPathRenderer *pathRenderer = [[MKOverlayPathRenderer alloc] initWithOverlay:overlay];
pathRenderer.fillColor = [UIColor redColor];
pathRenderer.strokeColor = [UIColor magentaColor];
return pathRenderer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment