Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to launch Apple Maps from iOS app

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 860
    Comment on it

    Hi Readers!

    Below is the code to launch the Apple Maps application and display the directions between 2 points on Map.

    Example 1: Display directions

    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(42.313432,-71.057157) addressDictionary:nil];
        MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
        item.name = @"Boston";
        
        MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(35.843871,-78.645056) addressDictionary:nil];
        MKMapItem *item1 = [[MKMapItem alloc] initWithPlacemark:placemark1];
        item1.name = @"Raleigh";
        
        NSDictionary *options = @{
                                  MKLaunchOptionsDirectionsModeKey:
                                      MKLaunchOptionsDirectionsModeDriving,
                                  MKLaunchOptionsMapTypeKey:
                                      [NSNumber numberWithInteger:MKMapTypeSatellite],
                                  MKLaunchOptionsShowsTrafficKey:@YES
                                  };
        NSArray *arr = [NSArray arrayWithObjects:item,item1, nil];
        
        [MKMapItem openMapsWithItems:arr launchOptions:options];

    Here is the screenshot of Apple Maps App:

    You can change the parameters in the launch dictionary and have different results. If you pass nil then it will display the pins on map.

    Example 2: Display only annotations on map

    MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(42.313432,-71.057157) addressDictionary:nil];
        MKMapItem *item = [[MKMapItem alloc] initWithPlacemark:placemark];
        item.name = @"Boston";
        
        MKPlacemark *placemark1 = [[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(35.843871,-78.645056) addressDictionary:nil];
        MKMapItem *item1 = [[MKMapItem alloc] initWithPlacemark:placemark1];
        item1.name = @"Raleigh";
        
        NSDictionary *options = @{
                                  MKLaunchOptionsMapTypeKey:[NSNumber numberWithInteger:MKMapTypeStandard],
                                  };
        NSArray *arr = [NSArray arrayWithObjects:item,item1, nil];
        
        [MKMapItem openMapsWithItems:arr launchOptions:options];

    Screenshot:

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: