2016-10-05 21 views
1

こんにちは、PolylineMKapviewに表示する必要があります。私はそれをしましたが、ルートに基づいてPolylineを表示する必要があります。私は場所を使用している場合は、私は前に表示する必要があります緯度と経度を格納するために私は助けてください前にPolylineを保存しようとしています。Mmapapviewのルートに基づいてポリラインを描画する方法

答えて

1
- (void)drowRoautLines_FromLocation:(CLLocationCoordinate2D)FromLocation ToLocation:(CLLocationCoordinate2D)ToLocation 
{ 
    MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:FromLocation 
               addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]]; 
    MKMapItem *srcMapItem = [[MKMapItem alloc]initWithPlacemark:source]; 
    [srcMapItem setName:@"Source"]; 

    MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:ToLocation 
                addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil]]; 
    MKMapItem *distMapItem = [[MKMapItem alloc]initWithPlacemark:destination]; 
    [distMapItem setName:@"Destination"]; 

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

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

    [direction calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) 
    { 
     [self ShowLoading:NO]; 

     NSLog(@"response = %@",response); 
     NSLog(@"error = %@",error); 
     NSArray *arrRoutes = [response routes]; 
     if (arrRoutes.count == 0) 
     { 
      //Show Error Message. 
     } 
     else 
     { 
      [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]); 

       [steps enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) 
       { 
        //NSLog(@"Rout Instruction : %@",[obj instructions]); 
       }]; 
      }]; 
     } 
    }]; 

} 
関連する問題