I have a mapView in my application (iOS7) where you can get directions from your current location to a fixed destination by clicking a button. The application shows a polyline between the source and destination. The question is, how do I enlarge the map to show the entire line?
- (IBAction)handleRoutePressed:(id)sender {
self.routeButton.enabled = NO;
self.routeDetailsButton.enabled = NO;
MKDirectionsRequest *directionsRequest = [MKDirectionsRequest new];
MKMapItem *source = [MKMapItem mapItemForCurrentLocation];
[directionsRequest setSource:source];
CLLocationCoordinate2D destinationCoords = CLLocationCoordinate2DMake(57.0496683, 9.9220121);
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) {
self.routeButton.enabled = YES;
if (error) {
NSLog(@"There was an error getting your directions");
return;
}
self.routeDetailsButton.enabled = YES;
_currentRoute = [response.routes firstObject];
[self plotRouteOnMap:_currentRoute];
}];
}
I tried with
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(destinationCoords, 150*METERS_PER_MILE, 150*METERS_PER_MILE);
[_mapView setRegion:viewRegion animated:YES];
But naturally, this gives me a fixed view every time.
source
share