0

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

1 回答 1

1

在 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"];
于 2013-03-29T13:03:00.490 回答