In my project I've to find out the route path between two locations with the help of latitude and longitude.
I'm using the following code for it
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[mapvw setDelegate:self];
[self mapp];
}
-(void)mapp
{
CLLocationCoordinate2D coordinateArray[2];
coordinateArray[0] = CLLocationCoordinate2DMake(28.6129, 77.2295);
coordinateArray[1] = CLLocationCoordinate2DMake(28.6562, 77.2410);
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:2];
[mapvw setVisibleMapRect:[self.routeLine boundingMapRect]]; //If you want the route to be visible
[mapvw addOverlay:self.routeLine];
}
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
if(overlay == self.routeLine)
{
if(nil == self.routeLineView)
{
self.routeLineView = [[MKPolylineView alloc] initWithPolyline:self.routeLine];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 3;
}
return self.routeLineView;
}
return nil;
}
With this code I'm getting the output on simulator like this
But I want the route map which shows direction by road not by straight line. Please help me to solve it i m in trouble from the last 2 days ....
To draw path between two lat long, you can use below code.
ViewController.h
ViewController.m
UPDATE : Swift 4
Hope it will help you out! Change lat long in above code as per your requirement.