iphone mkMapview 中 A pin 的自定义标注!! ....默认标注和自定义标注的数据不匹配

发布于 2024-11-24 01:55:59 字数 2683 浏览 2 评论 0原文

pinView Callout

我正在尝试为放置在mapView中的图钉进行自定义标注..我可以通过隐藏来做到这一点pinView 的默认标注并在那里显示我的自定义标注。 ()..一切工作正常...但唯一的问题是我无法为调用分配正确的信息..我已经显示了默认调用,其中信息与我的自定义调用不同。我已经附上了屏幕截图.....

这是我的代码

-(void)mapViewImplementaion
{

    [mapview setMapType:MKMapTypeStandard];
    mapview.showsUserLocation=YES;


    for (int i =0;i<[allResultsArr count];i++)
    {
        List_Map_details *object=[allResultsArr objectAtIndex:i];

        CLLocationCoordinate2D coordinat = {[object.lati floatValue], [object.longi floatValue]};

        [mapview setRegion:MKCoordinateRegionMake(coordinat, 
                                                      MKCoordinateSpanMake(0.027f, 0.027f))];



DisplayMapPark *ann = [[DisplayMapPark alloc] init]; 

        ann.title =[NSString stringWithFormat:@"%@",object.forRetailerName];
        ann.subtitle=[NSString stringWithFormat:@"%@ %@ %@",object.forAddress,object.forZipCode,object.forCityName];
        ann.latitude=[object.lati floatValue];
        ann.longitude=[object.longi floatValue];
        ann.coordinate = coordinat; 
        [mapview addAnnotation:ann];
        [ann release];



}




CalloutMapAnnotationView *calloutMapAnnotationView;

int m=1;


-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {

    MKAnnotationView *pinView = nil; 



// here i wrote some code for my custom callout to generate(not shown)


if(annotation != mapview.userLocation) 
    {

        //int i=0;
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

if ( pinView == nil ) 
            pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];


        NSString *imagName = [NSString stringWithFormat:@"%d.png", m];
        UIImage *image = [UIImage imageNamed:imagName];
        [pinView setImage:image];

        pinView.canShowCallout = NO;
        // To show this in scrren Shot i set it to Yes;


        [pinView setAnnotation:annotation];

        pinView.tag=m;

        UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=rightButton;
        //pinView.rightCalloutAccessoryView.frame=CGRectMake(0, 0, 60, 60);

        m++;
    } 

    else 
    {
        [mapview.userLocation setTitle:@"Ik ben hier"];


    }

    pinView.annotation = annotation;
    [rightButton release];
    return pinView;

}

嗨,如果有人知道这一点..请帮忙!!!!!

pinView Callout

I am trying for a custom callout for a pin dropped in a mapView .. I am able to do this by hiding the default callout of pinView and showing my custom call out there. ().. everything is working fine ... But only prob is i am not able to assign the correct information for the call out ..I had shown the Default call out in which info is different than my custom call out. I ve attached the scrren shot .....

Here is my code

-(void)mapViewImplementaion
{

    [mapview setMapType:MKMapTypeStandard];
    mapview.showsUserLocation=YES;


    for (int i =0;i<[allResultsArr count];i++)
    {
        List_Map_details *object=[allResultsArr objectAtIndex:i];

        CLLocationCoordinate2D coordinat = {[object.lati floatValue], [object.longi floatValue]};

        [mapview setRegion:MKCoordinateRegionMake(coordinat, 
                                                      MKCoordinateSpanMake(0.027f, 0.027f))];



DisplayMapPark *ann = [[DisplayMapPark alloc] init]; 

        ann.title =[NSString stringWithFormat:@"%@",object.forRetailerName];
        ann.subtitle=[NSString stringWithFormat:@"%@ %@ %@",object.forAddress,object.forZipCode,object.forCityName];
        ann.latitude=[object.lati floatValue];
        ann.longitude=[object.longi floatValue];
        ann.coordinate = coordinat; 
        [mapview addAnnotation:ann];
        [ann release];



}




CalloutMapAnnotationView *calloutMapAnnotationView;

int m=1;


-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {

    MKAnnotationView *pinView = nil; 



// here i wrote some code for my custom callout to generate(not shown)


if(annotation != mapview.userLocation) 
    {

        //int i=0;
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

if ( pinView == nil ) 
            pinView = [[[MKAnnotationView alloc]
                                          initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];


        NSString *imagName = [NSString stringWithFormat:@"%d.png", m];
        UIImage *image = [UIImage imageNamed:imagName];
        [pinView setImage:image];

        pinView.canShowCallout = NO;
        // To show this in scrren Shot i set it to Yes;


        [pinView setAnnotation:annotation];

        pinView.tag=m;

        UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=rightButton;
        //pinView.rightCalloutAccessoryView.frame=CGRectMake(0, 0, 60, 60);

        m++;
    } 

    else 
    {
        [mapview.userLocation setTitle:@"Ik ben hier"];


    }

    pinView.annotation = annotation;
    [rightButton release];
    return pinView;

}

Hi if any one is awre of this .. please help !!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久光 2024-12-01 01:55:59

我解决了这个问题。这是我的错误。我只是没有正确地将标签分配给引脚..当用户选择引脚时,我正在读取其他引脚的信息....谢谢大家

I solved this issue. It was the mistake by me. I was just not assigning the tags to the pins properly .. and when the user selects the pin i was reading some other pin's information.... Thanks all

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文