我想展示最短的路线。假设我在plist文件中有5个目的地,这意味着我有5条路线,但我想显示距离最短的目的地。
我写的以下代码并没有完成。
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"ROUTE_TRIP_1" ofType:@"plist"];
NSArray *pointsArray = [NSArray arrayWithContentsOfFile:thePath];
NSInteger pointsCount = pointsArray.count;
CLLocationCoordinate2D pointsToUse;
for(int i = 0; i < pointsCount; i++) {
CGPoint p = CGPointFromString(pointsArray[i]);
pointsToUse = CLLocationCoordinate2DMake(p.x,p.y);
// NSLog (@"total11 %.1f",_currentRoute.distance/1000);
NSLog (@"total %.1f",_currentRoute.distance/1000);}
//*********************************************************
// CLLocationCoordinate2D destinationCoords = CLLocationCoordinate2DMake(13.702668,100.488366);
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:pointsToUse addressDictionary:nil];
// MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:destinationCoords addressDictionary:nil];
MKMapItem *destination = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];
[directionsRequest setDestination:destination];
MKDirections *directions = [[MKDirections alloc] initWithRequest:directionsRequest];
[directions calculateDirectionsWithCompletionHandler:^(MKDirectionsResponse *response, NSError *error) {
// We're done
self.activityIndicator.hidden = YES;
[self.activityIndicator stopAnimating];
self.routeButton.enabled = YES;
// Now handle the result
if (error) {
NSLog(@"There was an error getting your directions");
//return;
}
// So there wasn't an error - let's plot those routes
self.routeDetailsButton.enabled = YES;
self.routeDetailsButton.hidden = NO;
_currentRoute = [response.routes firstObject];
[self plotRouteOnMap:_currentRoute];
}
}];