Monish Kumar
Monish Kumar

Reputation: 2848

multiple pins on mapview is not displayed in expected location in iphone sdk

Here I am facing a problem with the displaying of multiple pins at time on mapview. I am having 10 annotations with different location values instead the pins displaying at different places all are displayed at one point and here is my code for it

-(IBAction)searchMarinaAction
{
    MarinasListviewController *controller = [[MarinasListviewController alloc]initWithNibName:@"MarinasListviewController" bundle:nil];
    UIPopoverController *popoverView = [[UIPopoverController alloc]initWithContentViewController:controller];
    [popoverView setDelegate:self];

    marinasList = [controller.marinasListArray copy];
    NSMutableArray *pinsArray = [[NSMutableArray alloc]init];
    NSLog(@"\n marinas list count = %d",[marinasList count]);
    for(int i = 0; i < [marinasList count]; i++)
    {
        MarinaObject *obj = [marinasList objectAtIndex:i];
        NPAnnotation *annot = [[NPAnnotation alloc]init];
        annot.title = obj.marinaTitle;
        annot.subTitle = obj.marinaSubTitle;
        annot.marinaLocation = obj.marinaLocation;
        NSLog(@"\n %d. %@ , %@, %f, %f ",i, annot.title,     annot.subTitle,annot.marinaLocation.latitude,annot.marinaLocation.longitude);
        [pinsArray addObject:annot];

        isFromSearchMarina = YES;
        [annot release];
    }
    [mkView addAnnotations:pinsArray];
}



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



    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mkView dequeueReusableAnnotationViewWithIdentifier:@"Prospects"];

    if(pinView == nil) {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Prospects"];
        pinView.pinColor = MKPinAnnotationColorGreen;
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;

  }

Can anyone please help Where I am doing wrong.

Thanks to all, Monish

Upvotes: 0

Views: 551

Answers (1)

ggrana
ggrana

Reputation: 2335

Your annotation class, NPAnnotation, needs to implement the MKAnnotation, and for these you need to have a coordinate property.

You need to call marinaLocation as coordinate, and it need to be a CLLocationCoordinate2D.

Also your subTitle needs to be called subtitle.

From apple documentation:

An object that adopts this protocol must implement the coordinate property. The other methods of this protocol are optional.

Best regards, and hope it help you.

-

You also can take a look at: How to show the annotations in a mapView

Upvotes: 1

Related Questions