//跳到地图导航
- (void)btnPermanentAddressClick
{
NSString *appName = @"自己的app名字";
NSString *urlScheme = @"自己的urlScheme";
UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"选择地图" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * appleMap = [UIAlertAction actionWithTitle:@"苹果地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://"]])
{
//地理编码器
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"上海嘉定区伊宁路2000号" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
for (CLPlacemark *placemark in placemarks) {
//坐标(经纬度)
CLLocationCoordinate2D coordinate = placemark.location.coordinate;
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil]];
[MKMapItem openMapsWithItems:@[currentLocation, toLocation]
launchOptions:@{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsShowsTrafficKey: [NSNumber numberWithBool:YES]}];
}
}];
}else{
[NXPopAlertViewLabel showMessage:@"您的手机没有安装苹果地图"];
}
}];
UIAlertAction * baiduMap = [UIAlertAction actionWithTitle:@"百度地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://"]])
{
//地理编码器
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"上海嘉定区伊宁路2000号" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
for (CLPlacemark *placemark in placemarks) {
//坐标(经纬度)
CLLocationCoordinate2D coordinate = placemark.location.coordinate;
NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=driving&coord_type=gcj02",coordinate.latitude, coordinate.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}
}];
}else{
[NXPopAlertViewLabel showMessage:@"您的手机没有安装百度地图"];
}
}];
UIAlertAction * gaodeMap = [UIAlertAction actionWithTitle:@"高德地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"iosamap://"]])
{
//地理编码器
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"上海嘉定区伊宁路2000号" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
for (CLPlacemark *placemark in placemarks) {
//坐标(经纬度)
CLLocationCoordinate2D coordinate = placemark.location.coordinate;
NSString *urlString = [[NSString stringWithFormat:@"iosamap://navi?sourceApplication=%@&backScheme=%@&lat=%f&lon=%f&dev=0&style=2",appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}
}];
}else{
[NXPopAlertViewLabel showMessage:@"您的手机没有安装高德地图"];
}
}];
UIAlertAction * gugeMap = [UIAlertAction actionWithTitle:@"谷歌地图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]])
{
//地理编码器
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:@"上海嘉定区伊宁路2000号" completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
for (CLPlacemark *placemark in placemarks) {
//坐标(经纬度)
CLLocationCoordinate2D coordinate = placemark.location.coordinate;
NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?x-source=%@&x-success=%@&saddr=&daddr=%f,%f&directionsmode=driving",appName,urlScheme,coordinate.latitude, coordinate.longitude] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
}
}];
}else{
[NXPopAlertViewLabel showMessage:@"您的手机没有安装谷歌地图"];
}
}];
UIAlertAction * cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
}];
[alert addAction:appleMap];
[alert addAction:baiduMap];
[alert addAction:gaodeMap];
[alert addAction:gugeMap];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:^{
}];
}
IOS 跳转到百度地图,高的地图,谷歌地图进行导航
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 有时候需要快速实现或者需求需要,要跳转到其他地图应用实现导航,很简单,简单整理一下,请看代码~ De...
- 写在前面: 尽管精确度已然调至最佳, 但还是会有一定程度的定位误差, 作为开发者我已然尽力, 只能希望apple...
- 代码是swift 3.0,项目中传入的坐标是百度坐标,其中系统自带,高德,谷歌均使用高德地图sdk转换后的高德坐标...
- 目标 检测手机上安装的地图APP进行导航 功能实现 依次判断手机是否安装如下地图软件,检查到安装则跳转1、百度 地...