美文网首页
10.调用高德地图,百度地图,腾讯地图,苹果地图路线规划(无需集

10.调用高德地图,百度地图,腾讯地图,苹果地图路线规划(无需集

作者: bytebytebyte | 来源:发表于2020-11-07 07:12 被阅读0次
    20170407173754342.png
    1.调用百度地图 baidumap
    if ([[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:@"baidumap://map/"]]) {
                BMKPlanNode *start = [[BMKPlanNode alloc]init];
                start.name = handleHelper.address;
                start.pt = CLLocationCoordinate2DMake(weakSelf.locService.userLocation.location.coordinate.latitude, weakSelf.locService.userLocation.location.coordinate.longitude);
                BMKPlanNode *end = [[BMKPlanNode alloc]init];
                end.name = weakSelf.model.address;
                end.pt = CLLocationCoordinate2DMake([weakSelf.model.latitude doubleValue], [weakSelf.model.longitude doubleValue]);
                
                BMKOpenDrivingRouteOption *driveOpt = [[BMKOpenDrivingRouteOption alloc]init];
                driveOpt.appScheme = @"baidumapsdk://mapsdk.baidu.com";
                driveOpt.startPoint = start;
                driveOpt.endPoint = end;
                
                BMKOpenWalkingRouteOption *opt = [[BMKOpenWalkingRouteOption alloc]init];
                opt.appScheme = @"baidumapsdk://mapsdk.baidu.com";
                opt.startPoint = start;
                opt.endPoint = end;
                
                double distanceKM = [weakSelf distanceTwoPoint1:CLLocationCoordinate2DMake(handleHelper.latitude, handleHelper.longtitude)Point2:CLLocationCoordinate2DMake([_model.latitude doubleValue],[_model.longitude doubleValue])];
                if (distanceKM >= 3000.0) {
                    [BMKOpenRoute openBaiduMapDrivingRoute:driveOpt];
                }
                else
                {
                    [BMKOpenRoute openBaiduMapWalkingRoute:opt];
                }
            }
            else
            {
                [Tool MBProgressHUDWithTitle:@"没安装百度地图" OffsetY:kScreenWidth / 3 DelayTime:1.0f];
            }
    
    注意:经纬度不能传错,longitude经度,latitude纬度;传错的话百度地图会提醒,服务异常请稍后重试.
    
    2.调用高德地图 iosamap
    (1)第一种方式:
    AMapRouteConfig *config = [AMapRouteConfig new];
            config.appName = [self getApplicationName];
            config.appScheme = [self getApplicationScheme];
            config.startCoordinate = AMapCoordinateConvert( CLLocationCoordinate2DMake(_locService.userLocation.location.coordinate.latitude, _locService.userLocation.location.coordinate.longitude), AMapCoordinateTypeBaidu);
            config.destinationCoordinate = AMapCoordinateConvert(CLLocationCoordinate2DMake([_model.latitude doubleValue], [_model.longitude doubleValue]), AMapCoordinateTypeBaidu);  //百度sdk里边有百度坐标转高德坐标
            config.routeType = AMapRouteSearchTypeWalking;
            if (![AMapURLSearch openAMapRouteSearch:config]) {
                [Tool MBProgressHUDWithTitle:@"没安装高德地图" OffsetY:kScreenWidth / 3 DelayTime:1.0f];
            }
    
    (2)第二种方式
     // m 驾车:0:速度最快,1:费用最少,2:距离最短,3:不走高速,4:躲避拥堵,5:不走高速且避免收费,6:不走高速且躲避拥堵,7:躲避收费和拥堵,8:不走高速躲避收费和拥堵 公交:0:最快捷,2:最少换乘,3:最少步行,5:不乘地铁 ,7:只坐地铁 ,8:时间短 是  
    // t = 0:驾车 =1:公交 =2:步行  
    
        NSString *url = [[NSString stringWithFormat:@"iosamap://path?sourceApplication=applicationName&sid=BGVIS1&slat=%f&slon=%f&sname=%@&did=BGVIS2&dlat=%f&dlon=%f&dname=%@&dev=0&m=0&t=0",_locService.userLocation.location.coordinate.latitude, _locService.userLocation.location.coordinate.longitude, handleHelper.address, [_model.latitude doubleValue], [_model.longitude doubleValue],_model.address] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        if ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]])
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
        }
        else
        {
            [Tool MBProgressHUDWithTitle:@"没安装高德地图" OffsetY:kScreenWidth / 3 DelayTime:1.0f];
        }
    3.调用腾讯地图 qqmap
    -(void)openQMap
    {
        CLLocationCoordinate2D start = AMapCoordinateConvert(_locService.userLocation.location.coordinate, AMapCoordinateTypeBaidu);
        CLLocationCoordinate2D end = AMapCoordinateConvert(CLLocationCoordinate2DMake(self.coordinateY.floatValue, self.coordinateX.floatValue), AMapCoordinateTypeBaidu);
        NSString *url = [[NSString stringWithFormat:@"qqmap://map/routeplan?type=drive&from=%@&fromcoord=%f,%f&to=%@&tocoord=%f,%f&policy=0referer=Casing",self.startName,start.latitude,start.longitude,self.destinationName,end.latitude,end.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"qqmap://"]]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] options:@{} completionHandler:nil];
        }
    }
    4.调用苹果地图
    -(void)openAppleMap
    {
        MKPlacemark *startMark = [[MKPlacemark alloc]initWithCoordinate:_locService.userLocation.location.coordinate];
        MKMapItem *startItem = [[MKMapItem alloc]initWithPlacemark:startMark];
        startItem.name = self.startName;
        MKPlacemark *endMark = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(self.coordinateY.floatValue, self.coordinateX.floatValue)];
        MKMapItem *endItem = [[MKMapItem alloc]initWithPlacemark:endMark];
        endItem.name = self.destinationName;
        NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsMapTypeKey:[NSNumber numberWithInteger:MKMapTypeStandard],MKLaunchOptionsShowsTrafficKey:@YES};
    [MKMapItem openMapsWithItems:@[startItem,endItem] launchOptions:options];
    }
    

    相关文章

      网友评论

          本文标题:10.调用高德地图,百度地图,腾讯地图,苹果地图路线规划(无需集

          本文链接:https://www.haomeiwen.com/subject/vnofmktx.html