Created
November 28, 2012 05:01
-
-
Save benjaminpearson/4159123 to your computer and use it in GitHub Desktop.
Inlight Media - Blog - Using the iOS MapKit framework
This file contains hidden or 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
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 |
This file contains hidden or 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
double zoomLevel = [mapView getZoomLevel]; // getZoomLevel is implemented in the category | |
if(zoomLevel > 16) { | |
[mapView setCenterCoordinate:[mapView centerCoordinate] zoomLevel:16 animated:YES]; | |
} | |
} |
This file contains hidden or 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
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(); |
This file contains hidden or 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
NSString *url = [NSString stringWithFormat:@"http://maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]]; |
This file contains hidden or 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
(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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment