Powered By Blogger

Saturday, June 1, 2013

How to show direction inside a Mapview with iOS 6.0 in iphone?

Hey everyone,
  --- Now, with iOS 6.0 , To show direction from source - destination location in Apple's map application. Please check the below code to show the direction into MKMapView.

*** For Example :

CLLocationCoordinate2D coordinate;
coordinate.latitude = 0.0f; // Latitude of your source location
coordinate.longitude = 0.0f; // Longitude of your source location

        MKPlacemark* place = [[MKPlacemark alloc] initWithCoordinate: coordinate addressDictionary: nil];
        MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark: place];
        destination.name = @"Address of your destination";
        NSArray* items = [[NSArray alloc] initWithObjects: destination, nil];
        NSDictionary* options = [[NSDictionary alloc] initWithObjectsAndKeys:
                                 MKLaunchOptionsDirectionsModeDriving,
                                 MKLaunchOptionsDirectionsModeKey, nil];
        [MKMapItem openMapsWithItems: items launchOptions: options];



Thanks,
Nilesh M. Prajapati