700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > ios html调起高德地图 iOS 调用百度地图 高德地图 苹果自带的地图

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

时间:2022-12-13 16:00:26

相关推荐

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

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

高德:iosamap百度:baidumap

- (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:@""]]){

// 苹果地图

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

NSString *urlString = [[NSString stringWithFormat:@"/?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];

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。