应用内跳转到百度地图和苹果地图

本文介绍如何在iOS应用中集成苹果地图和第三方地图应用(如百度地图、高德地图),包括调用方法和使用场景,适用于开发者进行地图功能实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

调用苹果自家地图

-(void)testAppleMap{

//    CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(30.691793,104.088264);

//    CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(30.691293,104.088264);

    

    CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(39.915,116.404);

    CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(40.001,116.404);

    

    if (SYSTEM_VERSION_LESS_THAN(@"6.0")){

        // ios6以下,调用google map {

        NSString *urlString = [[NSString alloc] initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirfl=d", coords1.latitude,coords1.longitude,coords2.latitude,coords2.longitude];

        NSURL *aURL = [NSURL URLWithString:urlString]; //打开网页google地图

        [[UIApplication sharedApplication] openURL:aURL];

    }else// 直接调用ios自己带的apple map

    {

    //当前的位置 //

//    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

    //起点

    MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];

    //目的地的位置

    MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords2 addressDictionary:nil]];

    toLocation.name = @"目的地";

    NSArray *items = [NSArray arrayWithObjects:currentLocation, toLocation, nil];

    NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES }; //打开苹果自身地图应用,并呈现特定的item

    [MKMapItem openMapsWithItems:items launchOptions:options];

    }

}




- (void)testBaidu:(NSString *)title{

    BOOL hasBaiduMap = NO;

    BOOL hasGaodeMap = NO;

    

    if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]){

        hasBaiduMap = YES;

        NSLog(@"yesbaidu");

    }else

    {

        NSLog(@"nobaidu");

    }

    

    

    if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]){

        hasGaodeMap = YES;

    }

    

    

    NSString *url2 = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:39.915,116.404|name:我的位置&destination=latlng:39.915,120.202|name:终点&mode=driving"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;

    

    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:url2]];

    

//    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]];

//    }

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值