zoukankan      html  css  js  c++  java
  • iOS-调用百度地图,苹果自带地图,高德地图,谷歌地图导航方法

    - (void)actionSheet : (ServiceNetworkModel *)model{
    
      __block NSString *urlScheme = @"demoURI://";
      __block NSString *appName = @"demoURI";
      __block CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(model.lat.doubleValue, model.lng.doubleValue);
    
      UIAlertController *alert = [UIAlertController  alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyle ActionSheet];
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com/"]]){
    
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
      MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
      MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate   addressDictionary:nil]];
      [MKMapItem openMapsWithItems:@[currentLocation, toLocation] launchOptions:@{MKLaunchOptionsDirectionsModeKey:     MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
    
    }];
    
      [alert addAction:action];
    
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]){
    
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
      NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    
    }];
    
      [alert addAction:action];
    
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){
    
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
      NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    
    }];
    
      [alert addAction:action];
      
    }
    
    if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]){
    
      UIAlertAction *action = [UIAlertAction actionWithTitle:@"谷歌地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    
      NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
      [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }];   [alert addAction:action]; } UIAlertAction *action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:action]; [self presentViewController:alert animated:YES completion:^{ }]; }
  • 相关阅读:
    ctf web 百度杯”CTF比赛 九月场Upload i春秋
    ctf web 西普实验吧 登陆一下好吗 MySQL隐式转化 MySQL表达式的计算顺序
    Firefox 47.0.1
    给数组原型添加方法
    JS中几种常见的数组算法(前端面试必看)
    进制转换技巧解析
    redis通过6379端口无法连接服务器
    阿里云图片或文件上传 启动时报Error creating bean with name 'ossClient'问题
    20170628-三七互娱-测试工程师(提前批)
    20170514-vivo-软件工程师Java(提前批)
  • 原文地址:https://www.cnblogs.com/WJJ-Dream/p/5786514.html
Copyright © 2011-2022 走看看