调用第三方应用导航

#pragma mark 创建 actionSheet
-( void )navigationCompletion:( NSNotification *)notification {
   
// 接受 notification userInfo ,可以把参数存进此变量
   
NSDictionary *theData = [notification userInfo ];
   
NSString *latitude = [theData objectForKey : @"latitude" ];
   
NSString *longitude = [theData objectForKey : @"longitude" ];
   
NSLog ( @"latitude===%@,longitude===%@" ,latitude,longitude);
   
   
    [
self availableMapsApps :latitude longitude :longitude];
   
UIActionSheet *action = [[ UIActionSheet alloc ] init ];
   
    [action
addButtonWithTitle : @" 使用系统自带地图导航 " ];
   
for ( NSDictionary *dic in self . availableMaps ) {
        [action
addButtonWithTitle :[ NSString stringWithFormat : @" 使用 %@ 导航 " , dic[ @"name" ]]];
    }
    [action
addButtonWithTitle : @" 取消 " ];
    action.
cancelButtonIndex = self . availableMaps . count + 1 ;
    action.
delegate = self ;
    [action
showInView : self . view ];
}

- (
void )availableMapsApps:( NSString *)latitude longitude:( NSString *)longitude{
    [
self . availableMaps removeAllObjects ];
   
   
CLLocationCoordinate2D startCoor = self . mapView . userLocation . location . coordinate ;
   
NSLog ( @"startCoor.latitude===%f,startCoor.latitude===%f" ,startCoor. latitude ,startCoor. longitude );
   
CLLocationCoordinate2D endCoor = CLLocationCoordinate2DMake (latitude. floatValue + 0.01 , longitude. floatValue + 0.01 );
   
NSString *toName = @" AppName " ;
   
   
if ([[ UIApplication sharedApplication ] canOpenURL :[ NSURL URLWithString : @"baidumap://map/" ]]){
       
NSString *urlString = [ NSString stringWithFormat : @"baidumap://map/direction?origin=latlng:%f,%f|name: 我的位置 &destination=latlng:%f,%f|name:%@&mode=transit" ,
                               latitude.
floatValue , longitude. floatValue , endCoor. latitude , endCoor. longitude , toName];
       
       
NSDictionary *dic = @{ @"name" : @" 百度地图 " ,
                             
@"url" : urlString } ;
        [
self . availableMaps addObject :dic];
    }
   
if ([[ UIApplication sharedApplication ] canOpenURL :[ NSURL URLWithString : @"iosamap://" ]]) {
       
NSString *urlString = [ NSString stringWithFormat : @"iosamap://navi?sourceApplication=%@&backScheme=applicationScheme&poiname=fangheng&poiid=BGVIS&lat=%f&lon=%f&dev=0&style=3" ,
                              
@"AppN ame " , endCoor. latitude , endCoor. longitude ];
       
       
NSDictionary *dic = @{ @"name" : @" 高德地图 " ,
                             
@"url" : urlString } ;
        [
self . availableMaps addObject :dic];
    }
/*
     if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
     NSString *urlString = [NSString stringWithFormat:@"comgooglemaps://?saddr=&daddr=%f,%f¢er=%f,%f&directionsmode=transit", endCoor.latitude, endCoor.longitude, startCoor.latitude, startCoor.longitude];
    
     NSDictionary *dic = @{@"name": @"Google Maps",
     @"url": urlString};
     [self.availableMaps addObject:dic];
     }
     */
}

#pragma mark -actionSheet Delegate
- ( void )actionSheet:( UIActionSheet *)actionSheet clickedButtonAtIndex:( NSInteger )buttonIndex {
   
if (buttonIndex == 0 ) {
       
CLLocationCoordinate2D startCoor = self . mapView . userLocation . location . coordinate ;
       
CLLocationCoordinate2D endCoor = CLLocationCoordinate2DMake (startCoor. latitude + 0.01 , startCoor. longitude + 0.01 );
       
       
MKMapItem *currentLocation = [ MKMapItem mapItemForCurrentLocation ];
       
MKPlacemark *placemark = [[ MKPlacemark alloc ] initWithCoordinate :endCoor addressDictionary : nil ];
       
MKMapItem *toLocation = [[ MKMapItem alloc ] initWithPlacemark :placemark];
        toLocation.
name = @"to name" ;
       
        [
MKMapItem openMapsWithItems : @[ currentLocation, toLocation ]
                      
launchOptions : @{ MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving , MKLaunchOptionsShowsTrafficKey : [ NSNumber numberWithBool : YES ] } ];
       
    }
else if (buttonIndex < self . availableMaps . count + 1 ) {
       
NSDictionary *mapDic = self . availableMaps [buttonIndex- 1 ];
       
NSString *urlString = mapDic[ @"url" ];
        urlString = [urlString
stringByAddingPercentEscapesUsingEncoding : NSUTF8StringEncoding ];
       
NSURL *url = [ NSURL URLWithString :urlString];
       
BTLog ( @"\n%@\n%@\n%@" , mapDic[ @"name" ], mapDic[ @"url" ], urlString);
        [[
UIApplication sharedApplication ] openURL :url];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值