This is the code i have to draw directions to a location just as the normal iPhone maps application.
-(void)initUserCoords{
//NSLog(@"This if from new %@ %@", self.latitude, self.longitude);
double dLat = 59.2462;
double dLong = 15.1679;
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(dLat, dLong) addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
MKDirectionsRequest *request = [[MKDirectionsRequest alloc] init];
request.source = [MKMapItem mapItemForCurrentLocation];
request.destination = mapItem;
request.requestsAlternateRoutes = YES;
MKDirections *directions =
[[MKDirections alloc] initWithRequest:request];
[directions calculateDirectionsWithCompletionHandler:
^(MKDirectionsResponse *response, NSError *error) {
if (error) {
// Handle Error
} else {
[self showRoute:response];
}
}];
}
-(void)showRoute:(MKDirectionsResponse *)response
{
for (MKRoute *route in response.routes)
{
[self.mapView
addOverlay:route.polyline level:MKOverlayLevelAboveRoads];
}
}
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id < MKOverlay >)overlay
{
MKPolylineRenderer *renderer =
[[MKPolylineRenderer alloc] initWithOverlay:overlay];
renderer.strokeColor = [UIColor blueColor];
renderer.lineWidth = 5.0;
return renderer;
}
Now the problem is that nothing is being drawn. When the application is run my location is being shown but nothing happens afterwards. I appreciate any kind of help thank you!