Created
January 8, 2013 05:50
-
-
Save xuyunan/4481564 to your computer and use it in GitHub Desktop.
导航线路 (系统地图)
This file contains 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
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