iOS9下uri打开百度、高德、苹果地图

iOS9以前的可以通过

[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]

[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]

可以判读是否安装的百度地图与高德地图。而后通过

//打开百度地图导航

- (void)openBaiDuMap{

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:终点&mode=driving",currentLatitude, currentLongitude,_shopLat,_shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ;

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

}

//打开高德地图导航

- (void)openGaoDeMap{

NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=1&style=2",@"app name", @"YGche", @"终点", _shopLat, _shopLon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

}

//打开苹果自带地图导航

- (void)openAppleMap{

//起点

CLLocationCoordinate2D coords1 = CLLocationCoordinate2DMake(currentLatitude,currentLongitude);

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

//目的地的位置

CLLocationCoordinate2D coords2 = CLLocationCoordinate2DMake(_shopLat,_shopLon);

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

toLocation.name =address;

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

NSDictionary *options = @{ MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving, MKLaunchOptionsMapTypeKey: [NSNumber numberWithInteger:MKMapTypeStandard], MKLaunchOptionsShowsTrafficKey:@YES };

//打开苹果自身地图应用,并呈现特定的item

[MKMapItem openMapsWithItems:items launchOptions:options];

}

在更新iOS9后原来的方法不起做用了。解决办法:

在info.plist添加白名单

LSApplicationQueriesSchemes

     baidumap

     iosamap

你可能感兴趣的:(iOS9下uri打开百度、高德、苹果地图)