title: iOS Google Maps SDK replace marker icon
body: <p>I have a project where I need to display some markers on the map based on a location array we get. We are using custom marker pins and not the default. One requirement is that if we zoom in beyond a certain zoom threshold, we need to display bigger icons for the markers. So we have a small pin image and a big pin image. Based on zoom level, we need to display either the bigger or the smaller. I understand one way is to clear all markers and re-add them. However, due to some other challenge, that solution doesn't work for us. I need to simply replace the marker icon image. Following is my code:</p>
  
  <pre><code>-(void)updateMarkerImagePinSize {
  NSLog(@"Update Marker Image called");
  //[self.mapView clear];
  
  UIImage *pinImage;
  AtmLocations *atmLocations = [ATMLocatorManager sharedATMLocatorManager].atmLocations;
  CLLocationCoordinate2D searchedAddressCoordinate = CLLocationCoordinate2DMake(atmLocations.locations.startLatitude, atmLocations.locations.startLongitude);
  [self addSearchLocationMarkerToMap:searchedAddressCoordinate];
  
  NSArray *locationArray = atmLocations.locations.location;
  
  if (locationArray == nil || [locationArray count] == 0){
      return;
  }
  
  for (Location *location in locationArray) {
  
      CLLocationCoordinate2D markerCoordinate = CLLocationCoordinate2DMake([[[location attributes] latitude] doubleValue], [[[location attributes] longitude] doubleValue]);
  
      GMSMarker *marker = [GMSMarker markerWithPosition:markerCoordinate];
  
      if ([location.attributes.locationType isEqualToString:@"ATM"]) {
  
  
          if (self.mapView.camera.zoom &lt; kZoomThresoldForMarkerImageSizeChange) {
              pinImage = [UIImage imageNamed:@"atm_pin_small"];
          } else {
              pinImage = [UIImage imageNamed:@"atm_pin"];
          }
      } else {
  
          if (self.mapView.camera.zoom  &lt; kZoomThresoldForMarkerImageSizeChange) {
              pinImage = [UIImage imageNamed:@"office_pin_small"];
          } else {
              pinImage = [UIImage imageNamed:@"office_pin"];
          }
  
      }
  
  
      marker.map = nil;
      marker.icon = pinImage;
      marker.map = self.mapView;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>However, the issue I'm facing is that both the marker icon images remain. How can I replace the marker image and not show both?</p>