如何在同一纬度/长度上添加多个引脚

时间:2012-12-13 15:12:21

标签: iphone ios xcode annotations mkannotationview

我正在尝试在同一位置添加多个引脚。

for (int i = 0; i < [arrListing count]; i++) {


            List *obj = [arrListing objectAtIndex:i];
            NSLog(@"Title %@",obj.Title);

            CLLocationCoordinate2D annotationCoord;

            annotationCoord.latitude = [obj.lat floatValue];
            annotationCoord.longitude = [obj.log floatValue];

            MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
            annotationPoint.coordinate = annotationCoord;
            annotationPoint.title = obj.Title;

            [mapView addAnnotation:annotationPoint];
        }

上面的代码表示添加多个注释 但很多针都在同一个位置

所以我只能看到。 在那一点上的最后和最后一个。 下面是viewForAnnotation

的代码
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
     MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annView"];

    if (!annView) {
        annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annView"];
        annView.pinColor = MKPinAnnotationColorRed;
        annView.animatesDrop = YES;
        annView.canShowCallout = YES;
        NSLog(@"iRow :%d",iRow);
        annView.tag = iRow++;
        UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        annView.rightCalloutAccessoryView = rightButton;
        NSLog(@"if condition");
    }
    else
    {
        annView.annotation = annotation;
        NSLog(@"else condition");
    }
    return annView;
}

1 个答案:

答案 0 :(得分:0)

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinView = nil;
    if(annotation != map.userLocation)
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
    }
    else {
        [map.userLocation setTitle:@"I am here"];
    }
    return pinView;
}