iOS - 应用内部调用第三方地图进行搜索导航

判断手机应用是否包含相关地图应用,有就显示,没有就不显示相关跳转按钮
- (void)showSheet {
   
   UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择地图" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:nil, nil];
   if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]) {
       [sheet addButtonWithTitle:@"苹果地图"];
   }
   if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]){
       [sheet addButtonWithTitle:@"百度地图"];
   }
   if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
       [sheet addButtonWithTitle:@"高德地图"];
   }
   [sheet showInView:self.view];
}
跳转对应地图应用内进行导航
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSString *title = [actionSheet buttonTitleAtIndex:buttonIndex];
    
    if ([title isEqualToString:@"苹果地图"]) {
        MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
         CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(23.05,113.15);
        MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];
        //目的地名字
        toLocation.name = self.addressString;
        [MKMapItem openMapsWithItems:@[currentLocation, toLocation]
                       launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
    
    } else if ([title isEqualToString:@"高德地图"]) {
        NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&did=BGVIS2&dname=%@&dev=0&t=0",@"浙医二院"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    } else if ([title isEqualToString:@"百度地图"]) {
        NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/geocoder?src=%@&address=%@",@"andr.baidu.openAPIdemo",@"浙医二院"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    }
}

推荐阅读更多精彩内容

  • 文|萱哥 兰台读书 2016年维多利亚的秘密内衣秀将于巴黎当地时间11月30日举行,因为刘雯、何穗、奚梦瑶、雎晓雯...
    蓝枫123阅读 2,500评论 21 39
  • 无论科二科三技巧操作有多少,都离不开良好的学车基础。都说好的开始是成功的一半,今天小编就给你整理出一份史上最强的学...
    TT欧尼阅读 41评论 0 0
  • 想好这个标题时我还不知道该写什么内容,我也不知道该从何着手,只知道夜很静,静得甚至能听到自己的心跳声,天很黑,空气...
    我还有很多不知道阅读 57评论 0 1