I want to achieve this following route poly line view over Apple map.
And want to show poly line on road, which connect from source to destination.
my code for viewcontroller header file is...
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@interface TrackViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (strong,nonatomic) NSMutableArray *arrAnnotation;
@property (nonatomic, retain) MKPolyline *polyLine;
@property (nonatomic, retain) MKPolylineView *polyLineView;
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLLocation *currentLocation;
my code for viewcontroller implementation file is...
- (void)viewDidLoad {
[super viewDidLoad];
_mapView.showsUserLocation = YES;
if ([CLLocationManager locationServicesEnabled]) {
if (self.locationManager == nil) {
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
}
[self.locationManager startUpdatingLocation];
}
NSArray *name=[[NSArray alloc]initWithObjects:
@"Mumbai",
@"Chennai", nil];
self.arrAnnotation=[[NSMutableArray alloc]initWithCapacity:name.count];
MKPointAnnotation *mappin1, *mappin2;
CLLocationCoordinate2D location[3];
mappin1 = [[MKPointAnnotation alloc]init];
location[0] = CLLocationCoordinate2DMake(19.129275,72.905273);
mappin1.coordinate=location[0];
mappin1.title=[name objectAtIndex:0];
[self.arrAnnotation addObject:mappin1];
mappin2 = [[MKPointAnnotation alloc]init];
location[1] = CLLocationCoordinate2DMake(13.063426,80.288086);
mappin2.coordinate=location[1];
mappin2.title=[name objectAtIndex:1];
[self.arrAnnotation addObject:mappin2];
[self.mapView addAnnotations:self.arrAnnotation];
self.mapView.mapType = MKMapTypeStandard;
self.mapView.showsUserLocation = YES;
self.polyLine = [MKPolyline polylineWithCoordinates:location count:2];
[self.mapView setVisibleMapRect:[self.polyLine boundingMapRect]];
[self.mapView addOverlay:self.polyLine];
}
Please help me... Thanks in advance.