Home > Software design >  Google Map getting crashed after drawing around more than 1300 markers with custom color setting ico
Google Map getting crashed after drawing around more than 1300 markers with custom color setting ico

Time:12-01

I can draw more than around 8000 default red markers without setting icon property for marker. But I want to draw markers with different colors depending upon marker's value. In XCOde I get below warning:-

((null)) was false: Reached the max number of texture atlases, can not allocate more.
((null)) was false: Failed to get the icon for the given CGImageRef.
((null)) was false: Failed to allocate texture space for marker

from Google Map SDK & after that around 1300 markers it gets crashed. Is there any other way to set different colors to markers without crashing for more than 1300 markers.

I am setting marker's colour like below:-

marker.icon = GMSMarker.markerImage(with: self.getColorsFromString(strColor: strColor))

 func getColorsFromString(strColor:String) -> UIColor
{
    var color = UIColor()
    
    switch strColor {
    case "GREEN":
        color = UIColor.green
    case "YELLOW":
        color = UIColor.yellow
    case "RED":
        color = UIColor.red
    case "ORANGE":
        color = UIColor.orange
    case "BLUE":
        color = UIColor.blue
    case "CYAN":
        color = UIColor.cyan
    case "MAGENTA":
        color = UIColor.magenta
        
    default:
        color = UIColor.red
        print("default color")
    }
    return color
    
}

CodePudding user response:

How about to use struct of image? Wo do not need to call GMSMarker.markerImage() thousands times.

struct MarkerImage {
  static let green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
  static let yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
  static let red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
}

func getIcon(color: String) -> Image {
  switch(color) {
     case "GREEN": return MarkerImage.green
     case "YELLOW": return MarkerImage.yellow
     default: return MarkerImage.red
  }
}

marker.icon = getIcon(color)

If it works, we could create an enum of the color names, and extend that to return an image.

  • Related