如何绘制一条线来连接地图上的两个引脚?

时间:2013-03-28 18:23:37

标签: ios map mkmapview pins

我在地图上放了两个别针:

- (void)viewDidLoad {
    [super viewDidLoad];

    CLLocationCoordinate2D cord1 = {.latitude = 44.508473, .longitude =  11.375828};
    CLLocationCoordinate2D cord2 = {.latitude = 44.508871, .longitude =  11.375854};

    [self.mapView setRegion:MKCoordinateRegionMake(cord1, MKCoordinateSpanMake(.005, .005)) animated:YES];
    [self.mapView setRegion:MKCoordinateRegionMake(cord2, MKCoordinateSpanMake(.005, .005)) animated:YES];


    AddressAnnotation * annotazione = [[AddressAnnotation alloc] init];
    AddressAnnotation * annotazione2 = [[AddressAnnotation alloc] init];

    [annotazione setCoordinate:cord1];
    [annotazione2 setCoordinate:cord2];

    [self.mapView addAnnotation:annotazione];
    [self.mapView addAnnotation:annotazione2];
}

有没有办法将引脚与线连接?谢谢!

2 个答案:

答案 0 :(得分:2)

MKPolyline使用方法polylineWithCoordinates:count:,它采用了许多坐标。您已经拥有了所需的两个坐标(cord1cord2)来创建折线。将叠加层添加到地图中并实施mapView:viewForOverlay:以返回叠加层视图。

答案 1 :(得分:1)

在iOS 4.x中,Apple增加了对地图叠加的支持。可能有助于阅读更多有关MKPolyline& amp; MKPolylineView类和MKViewViewDelegate协议中定义的mapView:viewForOverlay:方法。所有这些都可以在Map Kit框架参考中找到。