Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7368485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:41:13+00:00 2026-05-29T03:41:13+00:00

In my viewDidLoad: method I have set the MapView like this so that if

  • 0

In my viewDidLoad: method I have set the MapView like this so that if user has selected all the locations then it should show all the locations/pin views and if only one then only one pin view should be shown.

- (void)viewDidLoad{

[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];

if ([vehicleLabel.text isEqualToString:@"All Vehicles"]) {

    MKCoordinateRegion region = {{0.0, 0.0},{0.0, 0.0}};
    region.center.latitude = 41.01860;
    region.center.longitude = 28.96470;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapView setRegion:region animated:YES];

    [mapView setDelegate:self];

    Annotations *ann = [[Annotations alloc] init];
    ann.title = @"Vehicle A";
    ann.subtitle = @"VG 1";
    ann.coordinate = region.center;

    [mapView addAnnotation:ann];

    NSMutableArray* annotations=[[NSMutableArray alloc] init];

    CLLocationCoordinate2D theCoordinate1;
    theCoordinate1.latitude = 41.01760;
    theCoordinate1.longitude = 30.96470;

    CLLocationCoordinate2D theCoordinate2;
    theCoordinate2.latitude = 41.01860;
    theCoordinate2.longitude = 31.96470;

    CLLocationCoordinate2D theCoordinate3;
    theCoordinate3.latitude = 41.01360;
    theCoordinate3.longitude = 25.96470;

    CLLocationCoordinate2D theCoordinate4;
    theCoordinate4.latitude = 41.01560;
    theCoordinate4.longitude = 27.96470;

    Annotations* myAnnotation1=[[Annotations alloc] init];

    myAnnotation1.coordinate=theCoordinate1;
    myAnnotation1.title=@"Vehicle B";
    myAnnotation1.subtitle=@"Group 1";

    Annotations* myAnnotation2=[[Annotations alloc] init];

    myAnnotation2.coordinate=theCoordinate2;
    myAnnotation2.title=@"Vehicle C";
    myAnnotation2.subtitle=@"Group 1";

    Annotations* myAnnotation3=[[Annotations alloc] init];

    myAnnotation3.coordinate=theCoordinate3;
    myAnnotation3.title=@"Vehicle D";
    myAnnotation3.subtitle=@"Group 1";

    Annotations* myAnnotation4=[[Annotations alloc] init];

    myAnnotation4.coordinate=theCoordinate4;
    myAnnotation4.title=@"Vehicle E";
    myAnnotation4.subtitle=@" Group 1";

    [mapView addAnnotation:myAnnotation1];
    [mapView addAnnotation:myAnnotation2];
    [mapView addAnnotation:myAnnotation3];
    [mapView addAnnotation:myAnnotation4];

    [annotations addObject:myAnnotation1];
    [annotations addObject:myAnnotation2];
    [annotations addObject:myAnnotation3];
    [annotations addObject:myAnnotation4];

    NSLog(@"Annotations: %d",[annotations count]);
}
else {

MKCoordinateRegion region = {{0.0, 0.0},{0.0, 0.0}};
region.center.latitude = 41.01860;
region.center.longitude = 28.96470;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];

[mapView setDelegate:self];

Annotations *ann = [[Annotations alloc] init];
ann.title = @"Vehicle A";
ann.subtitle = @"VG 1";
ann.coordinate = region.center;

[mapView addAnnotation:ann];
}}

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

MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
    static NSString *defaultPinID = @"aPin";
    pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil )
        pinView = [[[MKPinAnnotationView alloc]
                   initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
} else {
}
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
return pinView;}

And in my PickerView didSelectRow method: I have implemented:

-(void)pickerView:(UIPickerView *)pickerViewG didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

if (component == kGroupComponent) {
    NSString *selectedState = [self.vehicleGroup objectAtIndex:row];
    NSArray *array = [groupVehicles objectForKey:selectedState];
    self.vehiclesList = array;
    [vehiclePicker selectRow:0 inComponent:kListComponent animated:YES];
    [vehiclePicker reloadComponent:kListComponent];
} 

NSInteger groupRow = [vehiclePicker selectedRowInComponent:kGroupComponent];
NSInteger vehicleRow = [vehiclePicker selectedRowInComponent:kListComponent];

NSString *group = [self.groupOfVehicles objectAtIndex:groupRow];
NSString *vehicle = [self.listVehicles objectAtIndex:vehicleRow];

groupLabel.text = [[NSString alloc] initWithFormat: @"%@", group];

vehicleLabel.text = [[NSString alloc] initWithFormat: @"%@", vehicle];

valueForOtherView = vehicleLabel.text;}

Here what I want to know is that what if user selects a single vehicle from the picker view then all other pin views/ locations should be hidden/removed from the view and the only selected location/ pin view should be shown.

How can I do that in this picker view didSelectRow method: ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:41:16+00:00Added an answer on May 29, 2026 at 3:41 am

    What I’m doing in a case similar to yours, is:

    1) remove first all the annotations

    for (id <MKAnnotation> anAnnotation in [NSArray arrayWithArray:mapView_.annotations]) {
        [mapView_ removeAnnotation:anAnnotation];
    }
    

    2) and then paint the ones selected:

    [mapView_ addAnnotation:myAnnotation];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple mapview that has the following viewdidload method and didupdate to
I have code that dynamically load 10 different textfields in viewdidload method now if
In my view controller's -viewDidLoad method, I call [myTextField becomeFirstResponder]; This works like a
I have a simple ViewController that looks like this: @interface MyViewController : UIViewController<UIScrollViewDelegate> {
I'm trying to create a UISearchDisplayController programmatically. I have a method which should set
I have an UIViewController that has two UIViews inside, whose layout (set in Interface
I have created several UI elements in the viewDidLoad method. I want to change
there is a method called viewDidLoad that execute a code when the view is
I am creating a MKMapView in a method named generateMap. From inside viewDidLoad, this
In my iPhone app I have a UIViewController that has a UITableView and another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.