調用第三方app導航

NSArray * allMapCategory = @[@"百度地圖", @"高德地圖",@"蘋果地圖"];

NSMutableArray * mapCategory = [[NSMutableArray alloc] initWithArray:allMapCategory];

NSURL *gaodeURL = [NSURL URLWithString:@"grammermao://grammermao.xhb.com"];

NSURL *baiduURL = [NSURL URLWithString:@"baidumapsdk://mapsdk.baidu.com"];

//baidumapsdk://mapsdk.baidu.com

BOOL gaode = [[UIApplication sharedApplication] canOpenURL:gaodeURL];

BOOL baidu = [[UIApplication sharedApplication] canOpenURL:baiduURL];

if (!gaode) {

????????? [mapCategory removeObject:@"高德地圖"];

}

if (!baidu) {

???????? [mapCategory removeObject:@"百度地圖"];

}

UIAlertController * alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[self.navigationController presentViewController:alert animated:NO completion:nil];

for (int i = 0; i < mapCategory.count; i++) {

UIAlertAction * action = [UIAlertAction actionWithTitle:mapCategory[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//

if ([mapCategory[i] isEqualToString:@"百度地圖"]) {

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=%@&mode=driving&coord_type=bd09ll",22.643, 114.048, @"東環(huán)二路水斗富豪新村"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

}

if ([mapCategory[i] isEqualToString:@"高德地圖"]) {

CLLocationCoordinate2D coord = [self hhTrans_GCGPS:CLLocationCoordinate2DMake(22.643, 114.048)];

NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&poiname=%@&lat=%f&lon=%f&dev=0&style=2",@"app name", @"app scheme", @"東環(huán)二路水斗富豪新村",coord.latitude, coord.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

}

if ([mapCategory[i] isEqualToString:@"蘋果地圖"]) {

MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(22.643, 114.05) addressDictionary:nil];

MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:placemark];

//? ? ? ? ? ? ? ? toLocation.name = @"to name";

[MKMapItem openMapsWithItems:@[currentLocation, toLocation]

launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];

}

}];

[alert addAction:action];

}

UIAlertAction * cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

[alert addAction:cancel];


//百度坐標轉換成火星坐標

-(CLLocationCoordinate2D)hhTrans_GCGPS:(CLLocationCoordinate2D)baiduGps

{

const double x_pi = M_PI * 3000.0 / 180.0;

CLLocationCoordinate2D googleGps;

double bd_x=baiduGps.longitude - 0.0065;

double bd_y=baiduGps.latitude - 0.006;

double z = sqrt(bd_x * bd_x + bd_y * bd_y) - 0.00002 * sin(bd_y * x_pi);

double theta = atan2(bd_y, bd_x) - 0.000003 * cos(bd_x * x_pi);

googleGps.longitude = z * cos(theta);

googleGps.latitude = z * sin(theta);

return googleGps;

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容