2015-03-31 3 views

Répondre

0
MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(37.776142, -122.424774) addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ]; 

MKMapItem *srcMapItem = [[MKMapItem alloc]initWithPlacemark:source]; 
[srcMapItem setName:@""]; 

MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(37.73787, -122.373962) addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ]; 

MKMapItem *distMapItem = [[MKMapItem alloc]initWithPlacemark:destination]; 
[distMapItem setName:@""]; 

MKDirectionsRequest *request = [[MKDirectionsRequest alloc]init]; 
[request setSource:srcMapItem]; 
[request setDestination:distMapItem]; 
[request setTransportType:MKDirectionsTransportTypeAny]; 

MKDirections *direction = [[MKDirections alloc]initWithRequest:request]; 

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

    NSLog(@"response = %@",response); 
    NSArray *arrRoutes = [response routes]; 
    [arrRoutes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 

     MKRoute *rout = obj; 

     MKPolyline *line = [rout polyline]; 
     [mapview addOverlay:line]; 
     NSLog(@"Rout Name : %@",rout.name); 
     NSLog(@"Total Distance (in Meters) :%f",rout.distance); 

     NSArray *steps = [rout steps]; 

     NSLog(@"Total Steps : %lu",(unsigned long)[steps count]); 
     NSMutableArray *stepsArray=[[NSMutableArray alloc] init]; 
     [steps enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { 
      NSLog(@"Rout Instruction : %@",[obj instructions]); 
      NSLog(@"Rout Distance : %f",[obj distance]); 
      [stepsArray addObject:[obj instructions]]; 
     }]; 

     [self myShowDirections:response]; 
     self.steps.text=[NSString stringWithFormat:@"%@",stepsArray]; 

Vous pouvez l'utiliser et obtenir ce que vous voulez.