iOS打开百度地图、高德地图导航

1、判断手机里是否已经安装了百度地图或者高德地图:

        BOOL hasBaiduMap = NO;  
        BOOL hasGaodeMap = NO;  
          
        if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]){  
            hasBaiduMap = YES;  
        }  
        if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]){  
            hasGaodeMap = YES;  
        }    

 2、选择打开对应的地图进行导航:

        if ([@"使用百度地图导航" isEqualToString:title])  
        {  
            NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",currentLat, currentLon,_shopLat,_shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;  
              
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];  
        }  
        else if ([@"使用高德地图导航" isEqualToString:title])  
        {  
            NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2",@"app name", yourscheme, @"终点", _shopLat, _shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];  
        }      

 

你可能感兴趣的:(iOS打开百度地图、高德地图导航)