AsimNet
AsimNet

Reputation: 61

how to remove particular markers from GMS?

I asked earlier how to show different markerInfoWindow in this question, and now I'm trying to delete a particular marker when the user clicks on the button on the left corner.

first in .h file :

NSMutableArray *ADSMarray;
GMSMarker *adsMarker;

Then I created Ads marker like this:

    for (int l=0 ; l<self.ADS.count; l++) {
    CLLocationCoordinate2D pos = CLLocationCoordinate2DMake([[[self.ADS objectAtIndex:l] objectForKey:@"lati"] doubleValue],[[[self.ADS objectAtIndex:l] objectForKey:@"longi"] doubleValue]);
    NSLog(@"Ads:: %f",[[[self.ADS objectAtIndex:l] objectForKey:@"longi"] doubleValue]);
    adsMarker = [[GMSMarker alloc]init];
    adsMarker.position=pos;
    //marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
    adsMarker.draggable = NO;
    adsMarker.appearAnimation=YES;
    NSMutableArray*tempArray = [[NSMutableArray
                                 alloc] init];
    [tempArray addObject:@"ADS"];
    [tempArray addObject:[self.ADS objectAtIndex:l]];

    adsMarker.userData = tempArray;
    adsMarker.map = mapView_;
    adsMarker.icon=[GMSMarker markerImageWithColor:[UIColor blueColor]];

}

then in IBAction to remove them I wrote:

for (int i =0; i<self.ADS.count; i++) {
       // adsMarker.map = nil;
        [adsMarker setMap:nil];
    }

Hi

Upvotes: 1

Views: 2498

Answers (3)

Raja Harris
Raja Harris

Reputation: 11

To remove all markers

mapView.clear()

To remove a specific marker

myMarker.map = nil

Upvotes: 0

Saleh AlDhobaie
Saleh AlDhobaie

Reputation: 311

if you want to remove all markers in MapView you can use clear method that already built in GSM ..

Example:

[self.mapView clear];

link: Remove a marker

and if you want to remove all markers with specific color you can use this code if the user click on blue markers button :

NSArray *blueMarkers = @[ markerBlue1, markerBlue2 ];
NSArray *greenMarkers = @[ markerGreen1, markerGreen2 ];
NSArray *purpleMarkers = @[ markerPurple1, markerPurple2 ];
for (GMSMarker *marker in blueMarkers ){
     marker.map = nil;
}

Upvotes: 2

Saxon Druce
Saxon Druce

Reputation: 17624

When you add a marker store a reference to it. Then when you want to remove it, set its map property to nil - that will remove it from the map.

Upvotes: 2

Related Questions