2016-08-14 6 views

答えて

0

ReapeatもlblRightAddressと同じプロセスです。

// NSString *location = lblLeftAddress.text; I hust checked with your address it worked. 
NSString *location = @"296 Broadway Blvd Santa Monica CA 90016"; 
     CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
     [geocoder geocodeAddressString:location 
        completionHandler:^(NSArray* placemarks, NSError* error){ 
         if (placemarks && placemarks.count > 0) { 
          CLPlacemark *topResult = [placemarks objectAtIndex:0]; 
          MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult]; 

          MKCoordinateRegion region = self.mapView.region; 
          region.span.longitudeDelta /= 8.0; 
          region.span.latitudeDelta /= 8.0; 

          [self.mapView setRegion:region animated:YES]; 
          [self.mapView addAnnotation:placemark]; 
         } 
        } 
     ]; 

output

+0

を訪問することができます。他の場所に置くべきでしょうか? – kh1090

+0

ブレークポイントを指定し、目印で値を取得しているかどうかを確認します。 – Nilesh

+0

私はこれをチェックしました。(NSString * location = @ "296 Broadway Blvd Santa Monica CA 90016";)働いています...私はスクリーンショットをつけています。 – Nilesh

0

ただ、ここでは送信元と送信先の座標を変更します。複数の基準については

#pragma mark - Show Route Direction 

-(void)loadRoute 
{ 
    MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(34.0207504,-118.69193) addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ]; 

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

    MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(37.757815,-122.5076406) 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:MKDirectionsTransportTypeAutomobile]; 

    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]; 
      [self.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]); 

      }]; 
     }]; 
    }]; 

} 

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay 
{ 

    if ([overlay isKindOfClass:[MKPolyline class]]) { 
     MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithOverlay:overlay]; 
     [renderer setStrokeColor:[UIColor blueColor]]; 
     [renderer setLineWidth:3.0]; 
     return renderer; 
    } 
    return nil; 
} 

あなたは私がのviewDidLoadでこのコードを配置、まだありません注釈と空白のマップを取得しています。このhere

関連する問題