我不需要这么多针脚,他们挤满了这个区域。我使用kml解析器的输出来绘制两点之间的路径,如何删除路径之间的额外引脚。我只需要用于开始和结束的引脚。如何从出现的KML中减少那些过多的红色引脚\。
// Locate the path to the route.kml file in the application's bundle
// and parse it with the KMLParser.
kml = [[KMLParser parseKMLAtPath:filePath] retain];
// Add all of the MKOverlay objects parsed from the KML file to the map.
NSArray *overlays = [kml overlays];
[map addOverlays:overlays];
// Add all of the MKAnnotation objects parsed from the KML file to the map.
NSArray *annotations = [kml points];
[map addAnnotations:annotations];
// Walk the list of overlays and annotations and create a MKMapRect that
// bounds all of them and store it into flyTo.
MKMapRect flyTo = MKMapRectNull;
for (id <MKOverlay> overlay in overlays) {
if (MKMapRectIsNull(flyTo)) {
flyTo = [overlay boundingMapRect];
} else {
flyTo = MKMapRectUnion(flyTo, [overlay boundingMapRect]);
}
} //overlay
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);
}
} ///annotation
// Position the map so that all overlays and annotations are visible on screen.
map.visibleMapRect = flyTo;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
return [kml viewForOverlay:overlay];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([[annotation title] isEqualToString:@"Destination"])
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenpin"];
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
return newAnnotation;
}
else if ([[annotation title] isEqualToString:@"Current Location"])
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"yellowpin"];
newAnnotation.pinColor = MKPinAnnotationColorPurple;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
return newAnnotation;
}
else {
return [kml viewForAnnotation:annotation];}
}
答案 0 :(得分:1)
通过此代码,[kml points]中的所有注释都会添加到地图上。
NSArray *annotations = [kml points];
[map addAnnotations:annotations];
如果您只想要第一个和最后一个注释,那么只需添加
即可NSArray *annotations = [kml points];
[map addAnnotation:[annotations lastObject]];
[map addAnnotation:[annotations objectAtIndex:0]];
答案 1 :(得分:0)
查看Apple WWDC 2011视频的link,“使用MapKit以地理位置可视化信息”,其中显示了用于聚类MKAnnotation
个对象的首选设计模式。