iOS9之前的能夠經過ios
[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]] [[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]]
能夠判讀是否安裝的百度地圖與高德地圖。然後經過git
//打開百度地圖導航 - (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後原來的方法不起作用了。解決辦法:app
在info.plist添加白名單url
<key>LSApplicationQueriesSchemes</key> <array> <string>baidumap</string> <string>iosamap</string> </array>