Skip to content

Instantly share code, notes, and snippets.

@xuyunan
Created January 8, 2013 05:50
Show Gist options
  • Save xuyunan/4481564 to your computer and use it in GitHub Desktop.
Save xuyunan/4481564 to your computer and use it in GitHub Desktop.
导航线路 (系统地图)
Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
// iOS 6 MKMapItem available
MKPlacemark* place = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(lat, lng) addressDictionary:nil];
MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:place];
destination.name = addrName;
NSArray *items = @[destination];
NSDictionary* options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};
[MKMapItem openMapsWithItems:items launchOptions:options];
} else {
// use pre iOS 6 technique
NSString *addr = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", [[MLUser currentUser] ulatitude], [[MLUser currentUser] ulongitude], lat, lng];
// NSString *addr = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%f,%f&daddr=Current Location",lat, lng];
NSURL *url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment