博客> 三种地图的路径规划跳转
三种地图的路径规划跳转
2020-01-06 23:58 评论:0 阅读:615 superjunjun
跳转 地图

{ //坐标系的转换,百度坐标系转到高德的 CLLocationCoordinate2D fromLocation = [BOCoordinateTransformation changeBd09ToGcj02WithLatitude:_currentLocation.latitude withLongitude:_currentLocation.longitude]; CLLocationCoordinate2D toLocation = [BOCoordinateTransformation changeBd09ToGcj02WithLatitude:self.detailInfo.latitude withLongitude:self.detailInfo.longitude]; if (buttonIndex == 0) { // 苹果自带地图的跳转,用的是高德数据所以也需要转化后跳转。 NSString *urlString = [[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%f,%f&saddr=%f,%f",toLocation.latitude, toLocation.longitude,fromLocation.latitude,fromLocation.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];

}else if (buttonIndex == 1){
  //高德地图的跳转 路径规划用的是path  导航用的是navigation
    NSString *urlString = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=%@&sid=BGVIS1&slat=%f&slon=%f&sname=我的位置&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&m=0&t=0",@"爱上岗",fromLocation.latitude,fromLocation.longitude,toLocation.latitude,toLocation.longitude,@"终点"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
    }else{
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"未安装高德地图" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alertView show];
    }

}else if (buttonIndex == 2){

//百度地图的跳转 NSString urlString = [[NSString stringWithFormat:@"baidumap://map/direction?origin={{我的位置}}&destination=latlng:%f,%f|name=目的地&mode=transit&coord_type=gcj02",self.detailInfo.latitude, self.detailInfo.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; }else{ UIAlertView alertView = [[UIAlertView alloc]initWithTitle:nil message:@"未安装百度地图" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alertView show]; } } }

收藏
0
sina weixin mail 回到顶部