使用Google Maps SDK for iOS优化自定义标记图片的性能

我最近在iOS应用程序中整合了Google Maps for iOS SDK。 这个应用程序旨在检索飞机的位置(包括飞机模型,经纬度,速度 – 飞机的基本价值),然后将其绘制在Google地图上。

现在,最近,API(我正在使用的)返回的飞机数量翻了一番,几乎翻了三倍。 我还没有问题,每次我尝试运行应用程序,它崩溃,给我以下错误:

((null)) was false: Reached the max number of texture atlases, can not allocate more. 

我在SDK的Google Code上find了这个问题页面: https : //code.google.com/p/gmaps-api-issues/issues/detail?id=5756 – 在这里,我相信这个问题与我崩溃是下降到我正在使用自定义标记图像的数量。 每架飞机模型都有不同的图像,这些图像在渲染时被加载,并被分配给GMSMarker的UIImage。

现在,我遇到的问题是大量的结果,我得到这个崩溃。 同时,我也希望为每个标记提供单独的图像。

我的问题是,有没有一种方法,而不是分配一个特定的飞机的UIImage每个标记,我可以参考一次每个图像,以优化性能?

感谢您的帮助,请让我知道,如果我没有让自己清楚!

再次遇到问题后,回答我自己的问题。

问题似乎是我分配一个单独的UIImage实例到每个标记。 这意味着当我在GMSMapView实例上绘制标记时,每个标记都有一个单独的UIImage。 这里简要介绍一下: 自定义标记图像 – Google Maps SDK for iOS 。

如果您使用相同的图像创build多个标记,请为每个标记使用相同的UIImage实例。 这有助于在显示多个标记时提高应用程序的性能。

我正在迭代一个对象列表来创build每个标记:

 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_; } 

所以在这里,我正在将图像复制到每个标记。 这占用了不必要的资源。 我的解决scheme:

 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_; } 

在for循环之外定义UIImage实例意味着图像是从每个标记引用的,而不是为每个标记重新渲染的。 内存使用率在这之后要低得多。

我的解决 ((null))为false:达到纹理图集的最大数量,无法分配更多。

您在创build标记时将位置信息保留在线程之外。

 OperationQueue.main.addOperation { let coordinates = CLLocationCoordinate2D(latitude:LatData!, longitude: longData!) let marker = GMSMarker(position: coordinates) marker.icon = GMSMarker.markerImage(with: .blue) for i in 0 ... self.DemandLong.count { marker.infoWindowAnchor = CGPoint(x: 0, y: 5) marker.map = self.MyExploreView marker.accessibilityLabel = "\(i)" //Marker Label print("Location Marker i:\(i)") } }