iOS下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>
    原文作者:刘登坛
    原文地址: https://segmentfault.com/a/1190000011272699
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞