简体   繁体   English

使用Google Maps SDK for iOS时,内存和CPU使用率非常高

[英]Very high memory and CPU usage when using Google Maps SDK for iOS

I am creating an app in which I have to show the registered users on the map. 我正在创建一个应用程序,我必须在地图上显示注册用户。 I have to display their profile pictures. 我必须显示他们的个人资料照片。 There can be many of them, may be 1000, 2000, or 3000. 可能有很多,可能是1000,2000或3000。

The problem is, by adding every image, its memory usage increases and the app slows down. 问题是,通过添加每个图像,其内存使用量增加,应用程序减慢。 For example, I am using just this piece of code: 例如,我只使用这段代码:

UIImageView * imgView = imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"like_r.png"]];
for(int i=0;i<1000;i++)
{
    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(31.4514885, 74.2642593);
    marker.iconView = imgView;
    marker.map=_mapView;
}

Is there a good way to show all users on the map? 有没有一种方法可以在地图上显示所有用户?

Try setting marker.tracksViewChanges = NO; 尝试设置marker.tracksViewChanges = NO; to allow the CPU to idle. 允许CPU空闲。

Alternatively, set marker.image = [UIImage imageNamed:@"like_r.png"]; 或者,设置marker.image = [UIImage imageNamed:@"like_r.png"]; instead of setting the iconView, which should have a similar effect. 而不是设置iconView,它应具有类似的效果。

These changes should help with CPU, but may not solve the memory-related issues. 这些更改应该有助于CPU,但可能无法解决与内存相关的问题。

if you are using custom marker and assigning that to customView property of marker, first you should set marker.tracksViewChanges = false 如果您使用自定义标记并将其指定给customView属性,首先应设置marker.tracksViewChanges = false

then if you want to animate your custom marker on selection: 然后,如果要在选择时为自定义标记设置动画:

you should enable marker.tracksViewChanges = true then after animation finished, set marker.tracksViewChanges = false 你应该启用marker.tracksViewChanges = true然后在动画完成后设置marker.tracksViewChanges = false

this trick lets you overcome the high cpu usage of google maps 这个技巧可以让你克服谷歌地图的高CPU使用率

There's no way a user can see all 1000 pins at the same time. 用户无法同时看到所有1000个引脚。 You should probably reduce the number of pins displayed by grouping close users together. 您应该通过将关闭用户分组在一起来减少显示的引脚数。 And when zoomed in you can seperate those pins by increasing grouping factor. 放大后,您可以通过增加分组因子来分离这些引脚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM