iphone - UICGDirectionsDelegate 函数未在 iPhone 中调用

标签 iphone ios direction mkmapview

我在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];
}
`  

最佳答案

在 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"];

关于iphone - UICGDirectionsDelegate 函数未在 iPhone 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14040686/

相关文章:

iphone - iOS开发,在当前 View 之上显示UIScrollView区域

iphone - 等待事件播放

Javascript Web 应用程序,控制 iPhone 缩放输入焦点和模糊

iphone - 将图像部分转换为黑白效果

ios - 链接到 UIViewController 的自定义 UIView - 如何处理按钮操作

maps - Google map API V3 - DirectionsRendererOptions 和 InfoWindow 中的自定义内容

显示特定位置的 iPhone 罗盘

android - 在 5.1 android 设备上绘制路线图时应用程序崩溃的问题

iphone - Facebook 提及标签不起作用

ios - 我可以在 Instagram 的标题中发送一个可以被用户点击的 url 链接吗