Created
July 29, 2013 20:30
-
-
Save rbsgn/6107546 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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