IOS_app内跳转第三方地图进行导航

-(BOOL)canOpenUrl:(NSString *)string {

return  [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:string]];

}

- (void)gothereWithAddress:(NSString *)address andLat:(NSString *)lat andLon:(NSString *)lon {

if ([self canOpenUrl:@"baidumap://"]) {///跳转百度地图

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%@,%@|name=%@&mode=driving&coord_type=bd09ll",lat, lon,address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

return;

}else if ([self canOpenUrl:@"iosamap://"]) {///跳转高德地图

NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%@&lon=%@&dev=0&style=2",@"神骑出行",@"TrunkHelper",lat, lon] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

return;

}else{////跳转系统地图

CLLocationCoordinate2D loc = CLLocationCoordinate2DMake([lat doubleValue], [lon doubleValue]);

MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

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

[MKMapItem openMapsWithItems:@[currentLocation, toLocation]

launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,

MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];

return;

}

}

你可能感兴趣的:(IOS_app内跳转第三方地图进行导航)