Hi i am beginner in IOS and in my project I am trying to construct the route when user walking or driving along the road
I am trying to get longitude and latitude values from GPS but root is not constructing, that means poly-line is not constructing between the coordinates and when i run the app exceptions are coming please help me some one (if there is mistakes please post working code instead of it)
My code is below:-
#import "ViewController.h"
#import "MyAnnotation.h"
#define spanone 0.01f;
@interface ViewController ()
{
    NSMutableArray* MainAnnotations;
    NSString * latitude;
    NSString * longtude;
}
@property (nonatomic, strong) MKPolylineView *lineView;
@property (nonatomic, strong) MKPolyline *polyline;
@end
@implementation ViewController
@synthesize mapobj;
- (void)viewDidLoad {
    [super viewDidLoad];
    locmanager = [[CLLocationManager alloc] init];
    [locmanager setDelegate:self];
    if ([locmanager respondsToSelector:@selector(requestAlwaysAuthorization)])
    {
        [locmanager requestAlwaysAuthorization];
    }
    [locmanager setDistanceFilter:100.0f];
    [locmanager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
    [locmanager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                               initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"didUpdateToLocation: %@", newLocation);
    CLLocation *currentLocation = newLocation;
    if (currentLocation != nil) {
        latitude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        longtude = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
        NSLog(@"latitude value %@",latitude);
        NSLog(@"longtude value %@",longtude);
    }
    [self createAnnotations];
}
- (void)createAnnotations
{
    //Region
    MKCoordinateRegion myRegion;
    //Center
    CLLocationCoordinate2D center;
    center.latitude = [latitude doubleValue];
    center.longitude = [longtude doubleValue];
    //span
    MKCoordinateSpan span;
    span.latitudeDelta = spanone
    span.longitudeDelta = spanone;
    //Myregion
    myRegion.center = center;
    myRegion.span = span;
    [mapobj setRegion:myRegion animated:YES];
    //create annotations
    CLLocationCoordinate2D myannotations;
    myannotations.latitude = [latitude doubleValue];
    myannotations.longitude = [longtude doubleValue];
    MainAnnotations = [[NSMutableArray alloc]init];
    CLLocationCoordinate2D new_coordinate = CLLocationCoordinate2DMake(myannotations.latitude, myannotations.longitude);
    [MainAnnotations addObject:[NSValue valueWithMKCoordinate:new_coordinate]];
    NSLog(@"array list %lu",(unsigned long)MainAnnotations.count);
    MyAnnotation * annotation = [[MyAnnotation alloc]init];
    annotation.coordinate = myannotations;
    annotation.title = @"Hi";
    annotation.subtitle = @"how are you";
    [mapobj addAnnotations:[NSArray arrayWithObjects:annotation,nil]];
    CLLocationCoordinate2D coordinate = [[MainAnnotations objectAtIndex:0] MKCoordinateValue];
    NSLog(@"array values %lu",coordinate);
    NSLog(@"main values is %d",mainValue);
    [self drawPolyline];
}
-(void)drawPolyline
{
    [mapobj removeOverlay:self.polyline];
    // create an array of coordinates from allPins
    CLLocationCoordinate2D coordinates[MainAnnotations.count];
    int i = 0;
    for (MyAnnotation *currentLoc in MainAnnotations) {
        coordinates[i] = currentLoc.coordinate;
        i++;
    }
    // create a polyline with all cooridnates
    MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coordinates count:MainAnnotations.count];
    [mapobj addOverlay:polyline];
    self.polyline = polyline;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKOverlayView* overlayView = nil;
    if(overlay == self.polyline)
    {
        //if we have not yet created an overlay view for this overlay, create it now.
        if (self.lineView) {
            [self.lineView removeFromSuperview];
        }
        self.lineView = [[MKPolylineView alloc] initWithPolyline:self.polyline];
        self.lineView.fillColor = [UIColor redColor];
        self.lineView.strokeColor = [UIColor greenColor];
        self.lineView.lineWidth = 10;
        overlayView = self.lineView;
    }
    return overlayView;
}
@end