First if you require specific route you will need some of its coordinates. Let's say you have some route coordinates as NSDictionary
objects like in the example below
{
Lat = 53.3478;
Lon = -6.2597;
}
Stored in NSArray
called routeLocations
then you can do the following:
CLLocationCoordinate2D routeCoord[routeLocations.count];
for (int i = 0; i < routeLocations.count; i++ )
{
id location =[routeLocations objectAtIndex:i];
routeCoord[i] = CLLocationCoordine2DMake([[location objectForKey:@"Lat"]floatValue], [[location objectForKey:@"Lon"]floatValue]);
}
// create your route Polyline
MKPolyline *poly = [MKPolyline polylineWithCoordinates:routeCoord count:routeLocations.count];
// first remove previously added overlays if any then add your newly created route polyline
[self.mapView addOverlay:poly];
If you require customization on your overlay you can implement the following For iOS >= 7
-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolyline *route = overlay;
MKPolylineRenderer *routeRenderer = [[MKPolylineRenderer alloc]initWithPolyline:route];
routeRenderer.strokeColor = [UIColor blueColor];
return routeRenderer;
}
}
Else use deprecated method
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKPolyline class]])
{
MKPolylineView *route = [[MKPolylineView alloc]initWithPolyline:overlay];
route.strokeColor = [UIColor blueColor];
return route;
}
}