Skip to content

Instantly share code, notes, and snippets.

@benjaminpearson
Created November 28, 2012 05:01

Revisions

  1. Benjamin Pearson revised this gist Nov 28, 2012. 4 changed files with 46 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions custom-pins.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    UIImage *annotationImage = [UIImage imageNamed:@"annotation-image"]; //NOTE: Using a UIImageView will not work
    annotationView.image = annotationImage; // NOTE: Make sure annotationView is an instance of MKAnnotationView, not MKPinAnnotation
    5 changes: 5 additions & 0 deletions retina-images.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(40, 60), NO, 2); //Set scale factor to 2 to cater for @2x images
    [pinBackground drawInRect:CGRectMake(0,0,40,60)];
    [pinForeground drawInRect:CGRectMake(4,4,32,32)];
    UIImage *pinImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    2 changes: 2 additions & 0 deletions routing-part-1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    NSString *url = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    37 changes: 37 additions & 0 deletions routing-part-2.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    (NSArray *)decodePolyLine:(NSMutableString *)encoded {
    [encoded replaceOccurrencesOfString:@"\\\\" withString:@"\\" options:NSLiteralSearch range:NSMakeRange(0, [encoded length])];
    [encoded replaceOccurrencesOfString:@"points:\"" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [encoded length])];

    NSInteger len = [encoded length];
    NSInteger index = 0;
    NSMutableArray *listCoordinates = [[NSMutableArray alloc] init];
    NSInteger lat=0;
    NSInteger lng=0;
    while (index < len - 1) {
    NSInteger b;
    NSInteger shift = 0;
    NSInteger result = 0;
    do {
    b = [encoded characterAtIndex:index++] - 63;
    result |= (b & 0x1f) << shift;
    shift += 5;
    } while (b >= 0x20);
    NSInteger dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lat += dlat;
    shift = 0;
    result = 0;
    do {
    b = [encoded characterAtIndex:index++] - 63;
    result |= (b & 0x1f) << shift;
    shift += 5;
    } while (b >= 0x20);
    NSInteger dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
    lng += dlng;
    NSNumber *latitude = [[NSNumber alloc] initWithFloat:lat * 1e-5];
    NSNumber *longitude = [[NSNumber alloc] initWithFloat:lng * 1e-5];
    CLLocation *loc = [[CLLocation alloc] initWithLatitude:[latitude floatValue] longitude:[longitude floatValue]];
    [listCoordinates addObject:loc];
    }

    return [NSArray arrayWithArray:listCoordinates];
    }
  2. Benjamin Pearson created this gist Nov 28, 2012.
    5 changes: 5 additions & 0 deletions panning-zooming.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    double zoomLevel = [mapView getZoomLevel]; // getZoomLevel is implemented in the category
    if(zoomLevel > 16) {
    [mapView setCenterCoordinate:[mapView centerCoordinate] zoomLevel:16 animated:YES];
    }
    }