判断app是否安装百度地图,并启动导航 ios

本文介绍了一种方法,通过调用BaiduMap API和GoogleMap URL来实现从当前位置到指定地点的路线导航。对于iOS平台,首先检查是否支持BaiduMap API,若支持则使用此API进行导航;若不支持,则调用GoogleMap URL。对于安卓平台,当系统版本高于6.0时,使用自带的地图应用进行导航;低于6.0时,调用GoogleMap URL。此外,文章还展示了如何使用MKMapItem类在苹果地图中显示起点和终点坐标,创建路线,并提供驾驶模式和交通状况选项。

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=driving",latitude, longitude, addrlati,addrlong] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];

}else{

if (!IS_OS_7_OR_LATER) {//6.0以下,调用googleMap
            
            //注意经纬度不要写反了
            NSString * loadString=[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%@",_detailModel.salon.addrlati.floatValue,_detailModel.salon.addrlong.floatValue,_detailModel.salon.addr];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:loadString]];
            
        }else{
            CLLocationCoordinate2D coord = CLLocationCoordinate2DMake(addrlati, addrlong);
            MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];//调用自带地图(定位)
            
            //显示目的地坐标。画路线
            
            MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coord addressDictionary:nil]];
            
            toLocation.name = _detailModel.salon.salonname;
            
            [MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil]
             
                           launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil]
                                                                     forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]];
        }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值