在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戈钢、路徑規(guī)劃
百度地圖(路徑規(guī)劃)
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]];
高德地圖(路徑規(guī)劃)
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]];
蘋果自帶地圖(路徑規(guī)劃)
// 起點位置
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 };
//打開蘋果自身地圖應(yīng)用,并呈現(xiàn)特定的item
[MKMapItem openMapsWithItems:items launchOptions:options];