如何在同一纬度/经度添加多个引脚 [英] how to add multiple pin at the same lat/long

查看:141
本文介绍了如何在同一纬度/经度添加多个引脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一位置添加多个引脚。

 的for(int i = 0; I< arrListing计数];我++){
            列表* OBJ = [arrListing objectAtIndex:i];
            的NSLog(@标题%@,obj.Title);            CLLocationCoordinate2D annotationCoord;            annotationCoord.latitude = [obj.lat的floatValue]
            annotationCoord.longitude = [obj.log的floatValue]            MKPointAnnotation * annotationPoint = [[MKPointAnnotation的alloc]初始化];
            annotationPoint.coordinate = annotationCoord;
            annotationPoint.title = obj.Title;            [图形页面addAnnotation:annotationPoint];
        }

以上code再present加入mulitiple注解
但许多销都在相同的位置

所以,我只能看到。
最后,在这一点上的倒数第二个。

下面是code为viewForAnnotation

   - (MKAnnotationView *)的MapView:(*的MKMapView)的MapView viewForAnnotation:(ID< MKAnnotation>){注解
     MKPinAnnotationView * annView =(MKPinAnnotationView *)[图形页面dequeueReusableAnnotationViewWithIdentifier:@annView];    如果(!annView){
        annView = [[MKPinAnnotationView页头] initWithAnnotation:注释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(@如果条件);
    }
    其他
    {
        annView.annotation =注释;
        的NSLog(@else条件);
    }
    返回annView;
}


解决方案

   - (MKAnnotationView *)的MapView:(*的MKMapView)毫伏viewForAnnotation:
(ID< MKAnnotation>)注释
{
    MKPinAnnotationView * pinView =零;
    如果(注释!= map.userLocation)
    {
        静态的NSString * defaultPinID = @com.invasive code.pin
        pinView =(MKPinAnnotationView *)[图dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        如果(pinView ==无)pinView = [[MKPinAnnotationView页头]
                                         initWithAnnotation:注释reuseIdentifier:defaultPinID];        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
    }
    其他{
        [map.userLocation的setTitle:@我在这里];
    }
    返回pinView;
}

I am trying to add multiple pin at the same location.

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];
        }

the above code represent adding mulitiple annotation but many pin are at the same location

So I can see only. last and the second last at that point. below is the code for the 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;
}

解决方案

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

这篇关于如何在同一纬度/经度添加多个引脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆