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添加白名單

<key>LSApplicationQueriesSchemes</key>

<array>

? ? ?<string>baidumap</string>

? ? ?<string>iosamap</string>

</array>

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容