1

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

- (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;


}
4

2 回答 2

0

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

于 2012-08-16T20:01:22.037 回答
0

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

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

于 2016-01-28T01:35:00.667 回答