IOS地图导航

时间:2013-10-24 08:24:59

标签: ios maps mapkit

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

1 个答案:

答案 0 :(得分: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]]];