Wednesday, 21 October 2015

Apple Map ( device Default ) With Path

Apple MAP WITH PATH



 1 ) set Delegate in .h file :- CLLocationManagerDelegate

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>


 2 ) Then Write this in Your method :-


 CLLocationManager *locationManager = [[CLLocationManager alloc] init] ;
    
    locationManager.delegate = self ;
    
    locationManager.distanceFilter = kCLDistanceFilterNone ;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest ;
    
    float mycurrentLatitude = locationManager.location.coordinate.latitude ;
    float mycurrentLongitude = locationManager.location.coordinate.longitude ;
    
    NSLog(@"%f",locationManager.location.coordinate.latitude);
    
    [locationManager startUpdatingLocation] ;
    [locationManager  requestWhenInUseAuthorization] ;
    
    //---------- destination Location
    
    CLLocationCoordinate2D cordinate = CLLocationCoordinate2DMake([_selectedLatitudeValue floatValue], [_selectedLongitudeValue floatValue]) ;
    MKPlacemark *eventPlaceMark = [[MKPlacemark alloc] initWithCoordinate:cordinate addressDictionary:nil] ;
    MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:eventPlaceMark] ;
    [mapItem setName:[NSString stringWithFormat:@"%@",_selectedEventAddress]];
    
    //---------- Current Location
    
    CLLocationCoordinate2D currentCordinate = CLLocationCoordinate2DMake(mycurrentLatitude , mycurrentLongitude ) ;
    MKPlacemark *currentPlaceMark = [[MKPlacemark alloc] initWithCoordinate:currentCordinate addressDictionary:nil] ;
    MKMapItem *currentMapItem = [[MKMapItem alloc] initWithPlacemark:currentPlaceMark] ;
    [currentMapItem setName:@"current location"];
    [MKMapItem openMapsWithItems:@[mapItem , currentMapItem] launchOptions:@{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving}] ;


No comments:

Post a Comment