我想在地图中的多个地址或位置设置 pin,然后在这个 pin 点之间画一条线。引脚和线将显示在地图中。我找到了一个代码,它只显示某个位置的 pin .. 这是我的代码。.
- (void)viewDidLoad {
[super viewDidLoad];
mapView.delegate=self;
NSMutableArray* annotations=[[NSMutableArray alloc] init];
for (int i =1; i <=10; i++) {
CLLocationCoordinate2D theCoordinate1;
if (i==1) {
theCoordinate1.latitude = 37.786996;
theCoordinate1.longitude = -122.419281;
}
if (i==2) {
theCoordinate1.latitude = 37.810000;
theCoordinate1.longitude = -122.477989;;
}
if (i==3) {
theCoordinate1.latitude = 37.80000;
theCoordinate1.longitude = -122.407989;
}
if (i==4) {
theCoordinate1.latitude = 37.82000;
theCoordinate1.longitude = -122.407989;
}
MyAnnotation* myAnnotation1=[[MyAnnotation alloc] init];
myAnnotation1.coordinate=theCoordinate1;
[mapView addAnnotation:myAnnotation1];
[annotations addObject:myAnnotation1];
}
MKMapRect flyTo = MKMapRectNull;
for (id <MKAnnotation> annotation in annotations) {
MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
if (MKMapRectIsNull(flyTo)) {
flyTo = pointRect;
} else {
flyTo = MKMapRectUnion(flyTo, pointRect);
}
}
mapView.visibleMapRect = flyTo;
}
我想在这些点之间画一条线。最后 它 看起来 像 一条 路径 , 并且 大头针 站在 这条 路径 或 线上 . 谢谢你提前。