2017-10-18 6 views
0

Je suis en train d'enlever tous les marqueurs existants de google maps, nous pouvons le faire par map.clear mais je ne veux pas tout enlever (polyligne, polygones) sur la carte, je veux juste ne supprimer que des marqueursComment supprimer tous les marqueurs de googlemap pas mapview.clear (ios objectif-c)

Je crée des marqueurs basés sur la matrice comptent

-(void)annotationCreationForCoordinatesOfArray:(NSMutableArray *)array 
{ 
    for (int i=0; i<array.count; i++) 
    { 
     CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[[array objectAtIndex:i] objectForKey:@"latitude"] doubleValue], [[[array objectAtIndex:i] objectForKey:@"longitude"] doubleValue]); 

     mark = [GMSMarker markerWithPosition:position]; 

     NSString *annoNumber = [NSString stringWithFormat:@"%i",i]; 
     mark.title = annoNumber; 
     mark.map = _mapView; 
     mark.tracksViewChanges = YES; 
     mark.draggable = YES; 
     mark.icon = [UIImage imageNamed:@"Mappin.png"]; 

    } 
} 
+0

rendre votre marqueur spécifique 'de nil'. –

+0

Si je mets marker = nil, ou marker.map = nil le seul dernier marqueur est enlevé –

+0

Non, pour cela, vous devez définir un identifiant pour chaque marqueur, puis récupérer ce marqueur particulier, puis le supprimer. –

Répondre

0

Essayez ce code son travail pour moi.

Créer tableau global

NSMutableArray *removalMarkerArray; 

Maintenant, ajoutez tous les marqueurs dans le tableau global

removalMarkerArray=[[NSMutableArray alloc]init]; 

-(void)annotationCreationForCoordinatesOfArray:(NSMutableArray *)array{ 

    for (int i=0; i<array.count; i++){ 

    CLLocationCoordinate2D position = CLLocationCoordinate2DMake([[[array objectAtIndex:i] objectForKey:@"latitude"] doubleValue], [[[array objectAtIndex:i] objectForKey:@"longitude"] doubleValue]); 

    mark = [GMSMarker markerWithPosition:position]; 

    NSString *annoNumber = [NSString stringWithFormat:@"%i",i]; 
    mark.title = annoNumber; 
    mark.map = _mapView; 
    mark.tracksViewChanges = YES; 
    mark.draggable = YES; 
    mark.icon = [UIImage imageNamed:@"Mappin.png"]; 

    [removalMarkerArray addObject:mark]; 

    } 
    } 

Alors où vous voulez effacer tous les marqueurs

for (GMSMarker *marker in removalMarkerArray){ 
     marker.map = nil; 
    }