gpt4 book ai didi

ios - 使用适用于 iOS 的 Google Maps SDK 优化自定义标记图像性能

转载 作者:IT王子 更新时间:2023-10-29 08:19:28 25 4
gpt4 key购买 nike

我最近将 Google Maps for iOS SDK 整合到一个 iOS 应用程序中。此应用旨在检索飞机的位置(包括飞机型号、纬度/经度、速度 - 飞机的基本值),然后将它们绘制在 Google map 上。

现在,最近,API(我正在使用的那架)返回的飞机数量翻了一番,几乎翻了三倍。之前我没有遇到任何问题,但每次我尝试运行该应用程序时,它都会崩溃,并出现以下错误:

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

我在 SDK 的 Google 代码上找到了这个问题页面:https://code.google.com/p/gmaps-api-issues/issues/detail?id=5756 - 在这里,我不得不相信我的崩溃问题归结为我使用的自定义标记图像的数量。每个飞机模型都有不同的图像,这些图像在渲染时加载,并将 UIImage 分配给 GMSMarker。

现在,我遇到的问题是大量的结果,我遇到了这个崩溃。同时,我还希望每个标记都有单独的图像。

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

感谢您的帮助,如果我没有说清楚,请告诉我!

最佳答案

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

问题似乎是我正在为每个标记分配一个单独的 UIImage 实例。这意味着当我在 GMSMapView 实例上绘制标记时,每个标记都有一个单独的 UIImage。此处对此进行了简要描述: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.

我正在遍历对象列表以创建每个标记:

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

所以在这里,我将图像复制到每个标记。这占用了比必要更多的资源。我的解决方案:

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 实例意味着图像是从每个标记引用的,而不是为每个标记重新渲染。在此之后内存使用率要低得多。

关于ios - 使用适用于 iOS 的 Google Maps SDK 优化自定义标记图像性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25555778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com