问题
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.
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?
回答1:
Try setting marker.tracksViewChanges = NO;
to allow the CPU to idle.
Alternatively, set marker.image = [UIImage imageNamed:@"like_r.png"];
instead of setting the iconView, which should have a similar effect.
These changes should help with CPU, but may not solve the memory-related issues.
回答2:
if you are using custom marker and assigning that to customView
property of marker, first you should set 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
this trick lets you overcome the high cpu usage of google maps
回答3:
There's no way a user can see all 1000 pins at the same time. 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.
来源:https://stackoverflow.com/questions/37116644/very-high-memory-and-cpu-usage-when-using-google-maps-sdk-for-ios