UICGDirectionsDelegate函数未在iphone中调用

UICGDirectionsDelegate函数未在iphone中调用,iphone,ios,direction,mkmapview,Iphone,Ios,Direction,Mkmapview,我在iphone的mapView中显示了从起点到终点的路线,我完成了。但一天后我打开了这个项目,它没有显示路线,因为没有调用UICGDirectionsDelegate函数。我不知道为什么会发生这种情况,请一些机构指导我关于这个问题。非常感谢,我的示例代码在这里` - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.

我在iphone的mapView中显示了从起点到终点的路线,我完成了。但一天后我打开了这个项目,它没有显示路线,因为没有调用UICGDirectionsDelegate函数。我不知道为什么会发生这种情况,请一些机构指导我关于这个问题。非常感谢,我的示例代码在这里`

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.
    if (diretions.isInitialized) {
        [self update];
    }

    routeOverlayView = [[UICRouteOverlayMapView alloc] initWithMapView:mapViews];

    diretions = [UICGDirections sharedDirections];
    diretions.delegate = self;

}



- (IBAction)backButton:(id)sender {

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)update {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

    UICGDirectionsOptions *options = [[UICGDirectionsOptions alloc] init];
    options.travelMode = travelMode;

    if (is_route) {

        startPoint = [NSString stringWithFormat:@"%f,%f",APPDELEGATE.user_latitude,APPDELEGATE.user_longitude];
        endPoint = [NSString stringWithFormat:@"%@,%@",routeObj.latitude,routeObj.longitude];
        destination = poiObj.english_title;

    }else {
        startPoint = [NSString stringWithFormat:@"%f,%f",APPDELEGATE.user_latitude,APPDELEGATE.user_longitude];
        endPoint = [NSString stringWithFormat:@"%@ ,%@",poiObj.latitude,poiObj.longitude];
        destination = routeObj.starting_poi_name;
    }


    [diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];

}

- (void)moveToCurrentLocation:(id)sender {
    [mapViews setCenterCoordinate:[mapViews.userLocation coordinate] animated:YES];
}

- (void)addPinAnnotation:(id)sender {
    UICRouteAnnotation *pinAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[mapViews centerCoordinate]
                                                                                 title:nil
                                                                        annotationType:UICRouteAnnotationTypeWayPoint];
    [mapViews addAnnotation:pinAnnotation];
}



#pragma mark <UICGDirectionsDelegate> Methods

- (void)directionsDidFinishInitialize:(UICGDirections *)directions {
    [self update];
}

- (void)directions:(UICGDirections *)directions didFailInitializeWithError:(NSError *)error {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Map Directions" message:[error localizedFailureReason] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alertView show];
}

- (void)directionsDidUpdateDirections:(UICGDirections *)directions {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

    // Overlay polylines
    UICGPolyline *polyline = [directions polyline];
    NSArray *routePoints = [polyline routePoints];
    [routeOverlayView setRoutes:routePoints];

    // Add annotations
    currentLocation = @"You are here";
    UICRouteAnnotation *startAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints objectAtIndex:0] coordinate]
                                                                                   title:currentLocation
                                                                          annotationType:UICRouteAnnotationTypeStart];
    UICRouteAnnotation *endAnnotation = [[UICRouteAnnotation alloc] initWithCoordinate:[[routePoints lastObject] coordinate]
                                                                                 title:destination
                                                                        annotationType:UICRouteAnnotationTypeEnd];

    [mapViews addAnnotations:[NSArray arrayWithObjects:startAnnotation, endAnnotation, nil]];
}



- (void)directions:(UICGDirections *)directions didFailWithMessage:(NSString *)message {
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Map Directions" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alertView show];
}
`  
-(void)viewDidLoad
{
[超级视图下载];
//从nib加载视图后,执行任何其他设置。
if(方向初始化){
[自我更新];
}
routeOverlayView=[[UICROUTEOVERLAYMPVIEW alloc]initWithMapView:MAPVIEW];
方向=[UICGDirections sharedDirections];
diretions.delegate=self;
}
-(iAction)backButton:(id)发送方{
[self.navigationController PopViewControllerInitiated:是];
}
-(无效)未收到记忆警告{
[超级记忆警告];
}
-(作废)更新{
[[UIApplication sharedApplication]设置网络活动指示器可见:是];
UICGDirectionsOptions*选项=[[UICGDirectionsOptions alloc]init];
options.travelMode=travelMode;
如果(是路线){
startPoint=[NSString stringWithFormat:@“%f,%f”,APPDELEGATE.user_纬度,APPDELEGATE.user_经度];
端点=[NSString stringWithFormat:@“%@,%@”,路由北京纬度,路由北京经度];
目的地=poiObj.english\u标题;
}否则{
startPoint=[NSString stringWithFormat:@“%f,%f”,APPDELEGATE.user_纬度,APPDELEGATE.user_经度];
端点=[NSString stringWithFormat:@“%@,%@”,poiObj.纬度,poiObj.经度];
destination=routeObj.starting_poi_name;
}
[diretions loadWithStartPoint:startPoint endPoint:endPoint options:options];
}
-(无效)移动到当前位置:(id)发件人{
[mapViews setCenterCoordinate:[mapViews.userLocation坐标]动画:是];
}
-(无效)addPinAnnotation:(id)发件人{
UICROUTEANNOTIONATION*PINANOTIONATION=[[UICROUTEANNOTIONATION alloc]initWithCoordinate:[地图视图中心坐标]
标题:无
注释类型:UICROUTEANNOTIONTYPEWAYPOINT];
[地图视图添加注释:pinAnnotation];
}
#pragma标记方法
-(无效)方向DidFinishInitialize:(UICGDirections*)方向{
[自我更新];
}
-(无效)方向:(UICGDirections*)方向初始化失败错误:(N错误*)错误{
[[UIApplication sharedApplication]设置网络活动指示器可见:否];
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“地图方向”消息:[错误本地化失败原因]委托:无取消按钮:无其他按钮:无确定,无];
[警报视图显示];
}
-(void)方向DidUpdateDirections:(UICGDirections*)方向{
[[UIApplication sharedApplication]设置网络活动指示器可见:否];
//重叠多段线
UICG多段线*多段线=[方向多段线];
NSArray*路由点=[多段线路由点];
[routeOverlayView设置路由:路由点];
//添加注释
currentLocation=@“您在这里”;
UICroudentAnnotation*StartAnotation=[[UICroudentAnnotation alloc]initWithCoordinate:[[routePoints objectAtIndex:0]坐标]
标题:当前位置
注释类型:uicroutAnnotationTypeStart];
UICroudeTanotation*endAnnotation=[[UICroudeTanotation alloc]initWithCoordinate:[[routePoints lastObject]坐标]
标题:目的地
注释类型:uicroutAnnotationTypeEnd];
[mapViews addAnnotations:[NSArray arrayWithObjects:StartAnotation,endAnnotation,nil];
}
-(void)方向:(UICGDirections*)方向DIDFILIWITHMESSAGE:(NSString*)消息{
[[UIApplication sharedApplication]设置网络活动指示器可见:否];
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“地图方向”消息:消息委托:无取消按钮:无其他按钮:无确定,无];
[警报视图显示];
}
`  
在UICGRoute.m中

替换这个

NSArray *stepDics;
NSDictionary *k;
for (int i = 0; i<allKeys.count; i++) {
k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:i]];
if ([k objectForKey:@"Steps"]) {
stepDics = [k objectForKey:@"Steps"];
break;
}
}
NSDictionary *k = [dictionaryRepresentation objectForKey:[allKeys objectAtIndex:[allKeys count] - 1]];
NSArray *stepDics = [k objectForKey:@"Steps"];