I have recently been incorporating the Google Maps for iOS SDK within an iOS app. This app is designed to retrieve position of aircraft (including aircraft model, lat/lng, speed - basic values for an aircraft) and then plot them on a Google Map.
Now, recently, the number of aircraft that the API (the one I am using) is returning has doubled, nearly tripled. I had no issues before yet each time I attempt to run the app, it crashes, giving me the following error:
((null)) was false: Reached the max number of texture atlases, can not allocate more.
I found this issue page on Google Code for the SDK: https://code.google.com/p/gmaps-api-issues/issues/detail?id=5756 - here, I am made to believe that the issue with my crash is down to the number of custom marker images I am using. Each aircraft model has a different image, and these are loaded as they are rendered and a UIImage assigned to a GMSMarker.
Now, the problem I have is with a large amount of results, I get this crash. At the same time, I also want to have individual images for each marker.
My question is, is there a way that instead of assigning each marker a UIImage of a specific aircraft, can I refer once to each image to optimise performance?
I appreciate your help, please let me know if I haven't made myself clear!
Answering my own question after coming across the issue again.
The problem appears to be that I am allocating a separate UIImage instance to each marker. This means that when I am plotting markers on the GMSMapView instance, each marker has a separate UIImage. This is described briefly here: Customize the marker image - Google Maps SDK for iOS.
If you are creating several markers with the same image, use the same instance of UIImage for each of the markers. This helps improve the performance of your application when displaying many markers.
I was iterating through a list of objects to create each marker:
for (int i = 0; i < [array count]; i++) {
UIImage *image = [UIImage imageWithContentsOfFile:@"image.png"];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(10, 10);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.icon = image;
marker.map = mapView_;
}
So here, I was copying the image to each marker. That took up more resources than necessary. The solution for me:
UIImage *image = [UIImage imageWithContentsOfFile:@"image.png"];
for (int i = 0; i < [array count]; i++) {
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(10, 10);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hello World";
marker.icon = image;
marker.map = mapView_;
}
Defining the UIImage instance outside of the for-loop meant that the image was referenced from each marker, not re-rendered for each marker. Memory usage was much lower after this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With