Skip to content

Instantly share code, notes, and snippets.

@davidolesch
Last active August 29, 2015 13:56
Show Gist options
  • Save davidolesch/9309876 to your computer and use it in GitHub Desktop.
Save davidolesch/9309876 to your computer and use it in GitHub Desktop.
Lesson 3 presented March 4th 2014
//DORouteMapViewController interface
@property (strong, nonatomic) MKPlacemark *origin;
@property (strong, nonatomic) MKPlacemark *destination;
//this method is called while transitioning from the search view to the map view
-(void)mapFromLocation:(NSString *)fromLocation toLocation:(NSString *)toLocation
{
//geocode the from location and handle the returned placemark
[[[CLGeocoder alloc] init] geocodeAddressString:fromLocation completionHandler:^(NSArray *placemarks, NSError *error) {
//grab the first placemark and set it as the origin placemark
self.origin = [[MKPlacemark alloc] initWithPlacemark:[placemarks firstObject]];
//add the origin placemark to the map
[self.mapView addAnnotation:self.origin];
//check if the destination has also been set
if (self.destination) {
//we have the origin and destination; next step is to getAndDisplayTravelTime
[self getAndDisplayTravelTime];
}
}];
//do the same process for the to location
[[[CLGeocoder alloc] init] geocodeAddressString:toLocation completionHandler:^(NSArray *placemarks, NSError *error) {
self.destination = [[MKPlacemark alloc] initWithPlacemark:[placemarks firstObject]];
[self.mapView addAnnotation:self.destination];
if (self.origin) {
[self getAndDisplayTravelTime];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment