-3

我有一个使用 mapkit 的小应用程序。我想实现导航。但我想利用 Iphone 中已有的地图应用程序,给它一个起点和目的地,并告诉它显示路线。

4

1 回答 1

2

试试这个,在 viewDidLoad

CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(42.777126,-76.113281);
    MKPlacemark *place = [[MKPlacemark alloc]initWithCoordinate:coords addressDictionary:nil];
    MKMapItem *toLocation = [[MKMapItem alloc]initWithPlacemark:place];


    MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];

    [toLocation setName:@"New York"];
    [currentLocation setName:@"San Fransico"];

    [MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil]
                   launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil]
                                                             forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]];
于 2013-10-24T08:33:55.310 回答