MapKit:跟踪路线

时间:2012-05-24 14:18:54

标签: objective-c xcode mapkit

我有一个包含当前位置和一个MkPointAnnotation的MapKit。我需要在这些点之间追踪路线。

- (void)viewDidLoad
{
    [super viewDidLoad];

    //esconder navBar
    [[self navigationController] setNavigationBarHidden:YES animated:NO];

    mapView.showsUserLocation = YES;
    UIBarButtonItem *zoomButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Onde Estou?"
                                   style:UIBarButtonItemStylePlain
                                   target: self
                                   action:@selector(zoomIn:)];

    self.navigationItem.rightBarButtonItem = zoomButton;

    UIBarButtonItem *typeButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Tipo"
                                   style:UIBarButtonItemStylePlain
                                   target: self
                                   action:@selector(changeMapType:)];

    self.navigationItem.leftBarButtonItem = typeButton;

    double lat = -21.21258;
    double lng = -47.816802;

    CLLocationCoordinate2D Coordinate;

    Coordinate.latitude = lat;
    Coordinate.longitude = lng;

    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
    annotationPoint.coordinate = Coordinate;
    annotationPoint.title = @"Ribeirão Shopping";
    annotationPoint.subtitle = @"Ribeirão Preto - SP";
    [self.mapView addAnnotation:annotationPoint]; 

    MKCoordinateRegion newRegion;
    newRegion.center.latitude = lat;
    newRegion.center.longitude = lng;
    [self.mapView setRegion:newRegion animated:YES];

    mapView.mapType = MKMapTypeStandard;


}

2 个答案:

答案 0 :(得分:0)

使用本机API是不可能的,您可以使用 - 通过JSON - Google Directions提供的HTTP服务

答案 1 :(得分:0)

使用MKDirectionReqeuest和MKDriectionResponse。 MKDirectionResponse有MKRoute,可以帮助你绘制线条。

可在此处找到文档(https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKDirectionsRequest_class/