- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after
loading the view, typically from a nib.
[self findRoute]; // ND: call new
function
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can
be recreated.
}
- (void) findRoute
{
MKDirectionsRequest * request =
[[MKDirectionsRequest alloc] init];
// CLLocationCoordinate2D srce2d =
{38.89751790, -77.0365419}; // Capitol, Washington DC
// CLLocationCoordinate2D dest2d =
{39.136772 , -77.714715 }; // Purcellville, VA
CLLocationCoordinate2D srce2d =
{51.500866, -0.142292}; // Buckingham Palace, England
CLLocationCoordinate2D dest2d =
{51.178865, -1.82677 }; // Stonehenge, England
MKPlacemark * sMK = [[MKPlacemark
alloc] initWithCoordinate:srce2d addressDictionary:NULL];
MKPlacemark * dMK = [[MKPlacemark
alloc] initWithCoordinate:dest2d addressDictionary:NULL];
request.source = [[MKMapItem
alloc] initWithPlacemark:sMK];
request.destination = [[MKMapItem
alloc] initWithPlacemark:dMK];
request.requestsAlternateRoutes = NO;
MKDirections * directions =
[[MKDirections alloc] initWithRequest:request];
[directions
calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse
* response, NSError *error) {
if (error) {
NSLog(@"We have an error: %@\n", [error description]);
} else {
[self showRoute:response];
}
}];
} // end method findRoute
- (void) showRoute: (MKDirectionsResponse *) response {
for (MKRoute * route in
response.routes) {
NSLog(@"Route:
%@\n", [route description]);
for
(MKRouteStep * step in route.steps) {
NSLog(@"Step: %@\n", step.instructions);
} // for each
step in that route
} // for each route
} // end method showRoute