- (void)navigationByMapLocationName:(NSString *)locationName lat:(NSString *)lat lon:(NSString *)lon {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * alertAction = [UIAlertAction actionWithTitle:@"使用苹果自带地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
// MKMapItem *location = [[MKMapItem alloc] ]
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]) addressDictionary:nil]]; //目的地坐标
toLocation.name = locationName; //目的地名字
[MKMapItem openMapsWithItems:@[currentLocation,toLocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:NO]}];
}];
[alertController addAction:alertAction];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
UIAlertAction * alertAction = [UIAlertAction actionWithTitle:@"使用百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (locationName) {
NSString *urlString;
urlString = [NSString stringWithFormat:@"baidumap://map/geocoder?address=%@&src=八度空间",locationName];
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}
}];
[alertController addAction:alertAction];
}
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
UIAlertAction * alertAction = [UIAlertAction actionWithTitle:@"使用高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if (locationName) {
NSString *urlString;
urlString = [NSString stringWithFormat:@"iosamap://poi?sourceApplication=八度空间&name=%@",locationName];
urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url];
}
}];
[alertController addAction:alertAction];
}
UIAlertAction *alertAction4 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alertController addAction:alertAction4];
[[ShareOpenUrl cyl_tabBarController] presentViewController:alertController animated:YES completion:nil];
}
网友评论