在iOS8中绘制两点之间的路径时获得空响应

时间:2014-11-05 12:31:09

标签: ios8 mkmapview

MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(_currentLocaton.coordinate, 1000, 1000);
MKCoordinateRegion adjustedRegion = [map regionThatFits:viewRegion];
[map setRegion:adjustedRegion animated:NO];

 MKPlacemark *source = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(coord.latitude, coord.longitude) addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];

 NSLog(@"%f %f", coord.latitude,coord.longitude);

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

 MKPlacemark *destination = [[MKPlacemark alloc]initWithCoordinate:CLLocationCoordinate2DMake(self.userEvents.locationCordinate.latitude, self.userEvents.locationCordinate.longitude) addressDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil] ];
 NSLog(@"%f %f", self.userEvents.locationCordinate.latitude,self.userEvents.locationCordinate.longitude);

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

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

  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 : %d",[steps count]);

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

我正在使用此代码,我完全获得源和目标(纬度和经度)但无法获得响应。每次我都得到Null Response。 任何帮助将不胜感激。

0 个答案:

没有答案