地图

在info.plist里面添加白名单

LSApplicationQueriesSchemes
1、判断是否安装了百度地图、高德地图
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]) {
    NSLog(@"安装了百度地图");
}else{
    NSLog(@"未安装百度地图");
}

if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
    NSLog(@"安装了高德地图");
}
else{
    NSLog(@"未安装高德地图");
}
2、路径规划
百度地图(路径规划)
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=40.007623,116.360582&destination=39.007623,116.360582&mode=driving&src=%@",[self getApplicationName]]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
BOOL isOpen = [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];

高德地图(路径规划)
NSString * urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=40.007623&slon=116.360582&sname=A&did=BGVIS2&dlat=%f&dlon=%f&dname=&dev=0&m=0&t=0",[self getApplicationName],39.007623,116.360582]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
BOOL isOpen = [[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];

苹果自带地图(路径规划)
// 起点位置
CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(40.007623,116.360582);
MKMapItem *currentLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coords1 addressDictionary:nil]];
currentLocation.name = @"北京";
//目的地的位置
CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(31.220012,121.480121);
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];

你可能感兴趣的:(地图)