Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 显示与方向指示相关联的正确图像_Objective C_Mapkit - Fatal编程技术网

Objective c 显示与方向指示相关联的正确图像

Objective c 显示与方向指示相关联的正确图像,objective-c,mapkit,Objective C,Mapkit,我使用下面的代码从我的位置获取方向并在列表视图中显示 -(void)getDirectionFromMyPosition:(id)sender{ Reachability *networkReachability = [Reachability reachabilityForInternetConnection]; NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];

我使用下面的代码从我的位置获取方向并在列表视图中显示

-(void)getDirectionFromMyPosition:(id)sender{

    Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
    if (!(networkStatus == NotReachable)) {
        MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
        [request setSource:[MKMapItem mapItemForCurrentLocation]];
        // Make the destination
        CLLocationCoordinate2D destinationCoords = CLLocationCoordinate2DMake(self.lat,self.lon);
        MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:destinationCoords addressDictionary:nil];
        MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];
        [request setDestination:destination];
        [request setTransportType:MKDirectionsTransportTypeAny]; // This can be limited to automobile and walking directions.
        [request setRequestsAlternateRoutes:YES]; // Gives you several route options.
        MKDirections *directions = [[MKDirections alloc] initWithRequest:request];


        [MBProgressHUD showHUDAddedTo:self animated:YES];
        dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{

            [directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {

                dispatch_async(dispatch_get_main_queue(), ^{
                    [MBProgressHUD hideHUDForView:self animated:YES];
                });


                if (!error) {

                    NSArray *routes=[response routes];
                    if(delegate && [delegate respondsToSelector:@selector(calculatedRoute::)]) {
                        [delegate calculatedRoute:routes :(UIButton*)sender];
                    }

                    for (MKRoute *route in routes) {
                        [self.mapView addOverlay:[route polyline] level:MKOverlayLevelAboveRoads]; // Draws the

                        [self.mapView setVisibleMapRect:[[route polyline] boundingMapRect] edgePadding:UIEdgeInsetsMake(35.0, 35.0, 35.0, 35.0) animated:YES];
                    }
                }else{
                    [self handleMapDirectionError];
                }
            }];
        });

    }else{
        [self handleNoInternet];
    }
}
但我不知道如何设置与路由指令关联的正确映像

我希望获得下图所示的结果:

到目前为止,我的残酷解决方案是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"directionsDetailTableCell";

DirectionsDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[DirectionsDetailTableViewCell  alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


/*********************/
/*Le API ad oggi non tornano nulla che possa far capire quale immagine usare*/
/*********************/
NSString *str=[[self.steps objectAtIndex:indexPath.row] instructions];
if(![str isEqualToString:@""]){

    UIImage *img=nil;
    if(([str rangeOfString:@"destinazione"].length!=0||[str rangeOfString:@"destination"].length!=0)){
        img=[UIImage imageNamed:@"destination.png"];
    }else if([str rangeOfString:@"Continua"].length!=0||[str rangeOfString:@"Proceed"].length!=0||[str rangeOfString:@"Continue"].length){
        img=[UIImage imageNamed:@"continues.png"];
    }else if([str rangeOfString:@"sinistra"].length!=0||[str rangeOfString:@"left"].length!=0){
        img=[UIImage imageNamed:@"left.png"];
    }else if ([str rangeOfString:@"destra"].length!=0||[str rangeOfString:@"right"].length!=0){
        img=[UIImage imageNamed:@"right.png"];
    }else if(([str rangeOfString:@"rotonda"].length!=0||[str rangeOfString:@"round"].length!=0)){
        img=[UIImage imageNamed:@"round.png"];
    }else if(([str rangeOfString:@"uscita"].length!=0||[str rangeOfString:@"exit"].length!=0)){
        img=[UIImage imageNamed:@"exit.png"];
    }

    if(img!=nil){
        cell.img.image=img;
    }

    cell.lbltitle.text=[[self.steps objectAtIndex:indexPath.row] instructions];
    cell.lbldescription.text=[NSString stringWithFormat:@"%f Km",[[self.steps objectAtIndex:indexPath.row] distance]/1000];
}

return cell;

}

尝试以下操作:计算相邻台阶的多段线之间的方位差(请参见)。如果差值在-30和+30之间,则说“继续”,如果差值在+30到+180之间,则说“右”,否则说“左”。好主意!但问题只是部分解决了。在这种模式下,我无法识别环形交叉口,也无法区分高速公路上的弯道和“出入口”。是的,只是部分。我在MKRouteStep中没有看到任何东西可以帮助自动解释指令,除了你的暴力方法。