Issue
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
Solution
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
Answered By - ggrana
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.