Add a whitelist to info.plist; otherwise, third-party applications cannot be opened. Steps are as follows: 1. In the info. Add LSApplicationQueriesSchemes plist, Type set to the Array Type 2. Add two elements to the array, both of type string (iosamap and baidumap), where iosamap represents autonavi map and baidumap represents baidumap

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>iosamap</string>
        <string>baidumap</string>
</array>
Copy the code

Then serve the dry goods

#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
Copy the code
UIAlertController * alertVC = [UIAlertController alertControllerWithTitle: @ "prompt message:" @ "navigation will jump to the third party App" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction * cancel = [UIAlertAction actionWithTitle: @ "cancel" style: UIAlertActionStyleCancel handler: nil]; UIAlertAction * amap = [UIAlertAction actionWithTitle: @ "gold map" style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _Nonnull action) { [self jumpToAmap]; }]; Baidu UIAlertAction * = [UIAlertAction actionWithTitle: @ "baidu map" style: UIAlertActionStyleDefault handler: ^ (UIAlertAction * _Nonnull action) { [self jumpToBaiduMap]; }]; UIAlertAction * appleMap = [UIAlertAction actionWithTitle: @ "Apple map" style: UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self jumpToAppleMap]; }]; [alertVC addAction:cancel]; [alertVC addAction:amap]; [alertVC addAction:baidu]; [alertVC addAction:appleMap]; [self presentViewController:alertVC animated:YES completion:nil];Copy the code
/* sourceApplication=%@&backScheme=%@ sourceApplication represents the name of your APP, which will be displayed later when you jump back, so must be specified. Dev =0 backScheme =0 backScheme =0 backScheme =0 backScheme =0 backScheme =0 backScheme =0 backScheme =0 backScheme */ - (void)jumpToAmap { if ( [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]){ CLGeocoder *geocoder = [[CLGeocoder alloc] init]; // We assume a terminal coordinate, [geocoder geocodeAddressString:@" Shanghai Jiading District 2000 Yining Road" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {for (CLPlacemark *placemark in Placemarks){// Coordinate (longitude and latitude) cllocationcoordinate = placemark.location.coordinate; NSString *urlString = [[NSString StringWithFormat: @ "iosamap: / / navi? SourceApplication = % @ & backScheme = % @ & lat f&dev f&lon = = % % = 0 & style = 2", @ "navigation," @ "AmapScheme", co ordinate.latitude, coordinate.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@NO} completionHandler:nil]; } }]; }else{NSLog(@" Amap is not installed on your iPhone, please install!" ); } #pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark - pragma mark Destination = latlng: % f, % f | name = destination Here the name field cannot be omitted, or navigation will fail, and the text to 3, Coord_type = gcj02 Coord_type allowed values are Bd09ll, gcj02, wGS84, if your APP map SDK uses Baidu map SDK, please fill bd09ll, otherwise fill Gcj02, */ - (void)jumpToBaiduMap {if ([[UIApplication sharedApplication] canOpenURL:[NSURL] ]){// CLGeocoder *geocoder = [[CLGeocoder alloc] init]; // We assume a terminal coordinate, [geocoder geocodeAddressString:@" Shanghai Jiading District 2000 Yining Road" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {for (CLPlacemark *placemark in Placemarks){// Coordinate (longitude and latitude) cllocationcoordinate = placemark.location.coordinate; NSString *urlString = [[NSString StringWithFormat: @ "baidumap: / / map/direction? Origin = {} {my position} & destination = latlng: % f, % f | name = destination & mode = driving&coord _type = gc j02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{UIApplicationOpenURLOptionUniversalLinksOnly : @NO} completionHandler:nil]; } }]; }else{// add a prompt NSLog(@" your iPhone is not installed Baidu Map, please install!" ); }} #pragma mark - jumpToAppleMap - (void)jumpToAppleMap {if ([UIApplication sharedApplication] CanOpenURL :[NSURL URLWithString:@"http://maps.apple.com/"]]){//MKMapItem Jump native maps (2) computing circuit MKMapItem * currentLocation = [MKMapItem mapItemForCurrentLocation]; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; // We assume a terminal coordinate, [geocoder geocodeAddressString:@" Shanghai Jiading Yining Road 2000号" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {CLPlacemark *endPlacemark = placemark.lastObject * endMKPlacemark = [[MKPlacemark alloc] initWithPlacemark: endPlacemark]; / / the map a point MKMapItem * endMapItem = (end) [[MKMapItem alloc] initWithPlacemark: endMKPlacemark]; / / MKLaunchOptionsDirectionsModeKey specified navigation model / / nsstrings * const MKLaunchOptionsDirectionsModeDriving; driving / / nsstrings * const MKLaunchOptionsDirectionsModeWalking; walk / / nsstrings * const MKLaunchOptionsDirectionsModeTransit; bus [MKMapItem openMapsWithItems: @ [currentLocation, endMapItem] launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}]; }]; }}Copy the code

Business flattery: fierce eagle