i have one UIViewcontroller with a MKMapKit and a PickerView.Like as shown below image.
and i have one plist which contains all co ordinates corresponding to the values in PickerView .So once i select any item from PickerView i will refresh the current Map and take the coordinates of new item (some times it may be 5 to 6 co-ordinates) and show that in map.
But for me i can see that "Annotations" are coming to map view but when i click another item the previous pins are still there in Map.
I want to show only annotations pins of selected PickerView item.Please help me
USE CASE:
this is my plist file
In my plist there one field called" categories" the items listed in Pickerview is teh total category list.
So when i scroll through PickerView i will check whether the selected item matching with any items in Plist category field.If its matching iam showing their co ordinates in map view.
But when i click "restuarents" category in PickerView i got following map which is correct.
and when i click "cluburi" category its supposed to show 2 Pins in Map instead of 3.Actually its not clearing the current "restuarent "Pin from the map .Like below image
So how do i clear the previous Pins in map before displaying new Pins?
This is my code in viewcontroller.m file
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [locations count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [locations objectAtIndex: row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
[_MAPVIEW setRegion:[_MAPVIEW region] animated:YES];
for(int j=0;j<[[savedContentsarray valueForKey:@"category"] count];j++)
{
if([[[savedContentsarray valueForKey:@"category"] objectAtIndex:j] isEqualToString:[locations objectAtIndex: row]])
{
coordinate.latitude=[[latitude objectAtIndex:j] floatValue];
coordinate.longitude=[[longitude objectAtIndex:j] floatValue];
annotation = [[myAnnotation alloc] initWithCoordinate:coordinate title:[[savedContentsarray valueForKey:@"name"]objectAtIndex:j]];
[_MAPVIEW addAnnotation:annotation];
}
}
}
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
//7
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
//8
static NSString *identifier = @"myAnnotation";
MKPinAnnotationView * annotationView = (MKPinAnnotationView*)[_MAPVIEW dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView)
{
//9
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
annotationView.pinColor = MKPinAnnotationColorPurple;
annotationView.animatesDrop = YES;
annotationView.canShowCallout = YES;
}else {
annotationView.annotation = annotation;
}
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
return annotationView;
}