Skip to content

Instantly share code, notes, and snippets.

@davidolesch
davidolesch / gist:9309897
Created March 2, 2014 17:15
Lesson 4 presented March 4th 2014
- (void)getAndDisplayTravelTime
{
//create request
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
[request setSource:[[MKMapItem alloc] initWithPlacemark:self.origin]];
[request setDestination:[[MKMapItem alloc] initWithPlacemark:self.destination]];
[request setTransportType:MKDirectionsTransportTypeAutomobile];
//send request
[[[MKDirections alloc] initWithRequest:request] calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
@davidolesch
davidolesch / gist:9309876
Last active August 29, 2015 13:56
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
@davidolesch
davidolesch / gist:9309862
Last active November 16, 2015 17:19
Lesson 2 presented March 4th 2014
//action connected to Random Location button
- (IBAction)touchedRandomLocation:(id)sender {
//create a list of cities
NSArray *cities = @[@"New York, NY",@"Los Angeles, CA",@"Chicago, IL",@"Philadelphia, PA",@"Phoenix, AZ",@"San Diego, CA",@"San Jose, CA",@"Jacksonville, FL",@"Indianapolis, IN",@"San Francisco, CA"];
//choose a random integer less than the count of cities
int randomIndex = arc4random_uniform((int)[cities count]);
//choose the city from the cities list at the random integer index
NSString *city = [cities objectAtIndex:randomIndex];
//DOMainViewController.m
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"1.png"]]];
//DOContactsTableViewController.h
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
UIImage *backgroundImage = [[UIImage imageNamed:@"newsfeed_background.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[backgroundView setImage:backgroundImage];
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[cell.contentView insertSubview:backgroundView belowSubview:cell.textLabel];