MapView аннотации / контакты в iPhone - PullRequest
1 голос
/ 30 января 2012

В моем методе viewDidLoad: я настроил MapView таким образом, чтобы, если пользователь выбрал все местоположения, он отображал все местоположения / виды выводов, и если только один, то должен отображаться только один вывод.

- (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;}

И в моем PickerView didSelectRow method: я реализовал:

-(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;}

Здесь я хочу знать, что если пользователь выбирает одно транспортное средство в окне выбора, а затем все остальные контактывиды / местоположения должны быть скрыты / удалены из вида, и должно быть показано только выбранное местоположение / представление булавки.

Как это сделать в этом окне выбора didSelectRow method:?

1 Ответ

0 голосов
/ 30 января 2012

То, что я делаю в случае, аналогичном вашему, это:

1) сначала удалите все аннотации

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

2), а затем закрасьте выбранные:

[mapView_ addAnnotation:myAnnotation];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...