// 需求是需要用戶 能從 所在位置 到 附近的健身房的 路線, 然而,就一個(gè)需求,不值當(dāng)?shù)奶砑右粋€(gè)地圖, 就用調(diào)用手機(jī)上第三方地圖軟件, ?什么高德, 百度, 騰訊, iOS 原生地圖都可以, 如果手機(jī)上什么地圖都沒有, 還有原生的 ?地圖, 如果連原生的地圖都刪除了, ?呵呵, ?那我就不管了, ?開玩笑, 如果連原生地圖都刪除了, 會(huì)跳轉(zhuǎn)到 ?appStore 下載, 蘋果自帶的軟件, 不會(huì)刪除, 只是把圖標(biāo)隱藏而已, 下載非澈苫纾快, 幾秒即可. 不影響什么
// 進(jìn)入正題
// 首先 添加白名單, 這是 必須的, 否則不能跳轉(zhuǎn), 添加在這里
LSApplicationQueriesSchemes
baidumap//百度
iosamap// 高德
comgooglemaps//谷歌
// 谷歌經(jīng)我親測, 在中國已廢, ?打開沒有內(nèi)容, 不用也罷
重點(diǎn)是打開的代碼
iOS 原生地圖
//當(dāng)前的位置
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
//目的地的位置
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude) addressDictionary:nil]];
toLocation.name = 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];
// 百度地圖
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {
UIAlertAction * baiduAction = [UIAlertAction actionWithTitle:@"百度地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=gcj02",latitude, longitude,name]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}];
}
// 高德地圖
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {
UIAlertAction * gaodeAction = [UIAlertAction actionWithTitle:@"高德地圖" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",@"一七健康",@"yiqihealth",latitude, longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
}];
}
運(yùn)行之后, 完美