ios html调起高德地图,iOS 调用百度地图, 高德地图,苹果自带的地图

在你项目的info.plist添加 LSApplicationQueriesSchemes 为KEY 类型为NSArray;添加对应的白名单

高德:iosamap百度:baidumap

b89d2e00f47f

- (void)click:(UIButton*)button{

// 百度地图与高德地图、苹果地图采用的坐标系不一样,高德和苹果只能用地名不能用后台返回的坐标

CGFloatlatitude  =36.547901;  // 纬度

CGFloatlongitude  =104.258354;// 经度

self.address = [[NSString alloc] init];

CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:(CLLocationDegrees)longitude];

CLGeocoder * geocoder = [[CLGeocoder alloc]init];

[geocoderreverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {

if(error ==nil&& [placemarkscount] >0) {

//这时的placemarks数组里面只有一个元素

CLPlacemark* placemark = [placemarksfirstObject];

NSLog(@"%@",placemark.addressDictionary); //根据经纬度会输出该经纬度下的详细地址  国家 地区 街道

self.address = [NSString stringWithFormat:@"%@",placemark.addressDictionary[@"FormattedAddressLines"][0]] ;

[self openAlert];

}

}];

}

- (void)openAlert{

CGFloatlatitude  =36.547901;  // 纬度

CGFloatlongitude  =104.258354;

CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:(CLLocationDegrees)longitude];

// 打开地图的优先级顺序:百度地图->高德地图->苹果地图

if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]]) {

// 百度地图

// 起点为“我的位置”,终点为后台返回的坐标

NSString *urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=%f,%f&mode=riding&src=%@", latitude, longitude,self.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL*url = [NSURLURLWithString:urlString];

[[UIApplication sharedApplication] openURL:url];

}else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"iosamap://"]]) {

// 高德地图

// 起点为“我的位置”,终点为后台返回的address

NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&sname=%@&did=BGVIS2&dname=%@&dev=0&t=0",@"我的位置",self.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

}else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://maps.apple.com"]]){

// 苹果地图

// 起点为“我的位置”,终点为后台返回的address

NSString *urlString = [[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%@",self.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

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

}else{

// 没有安装上面三种地图APP,弹窗提示安装地图APP

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"请安地图APP" message:@"建议安装百度地图APP" preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alertVC animated:NO completion:nil];

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值