Reputation: 645
I'm using Google Maps API for iOS, to display a map with a huge number of markers on it (~ 1200). Actually, it takes a really long time to display all this markers.
Would you recommend a solution or a framework which allows us to display only the markers on the visible map region ?
Thanks in advance.
Upvotes: 2
Views: 2826
Reputation: 1252
I develop an in-house app that has
The app started out using Apple Maps in the beginning then in the last months we switched to Google Maps. UPDATE: we switched back to Apple Maps due to performance issues :)
1: The performance of google maps is drastic.
If you are creating several markers with the same image, use the same instance of UIImage for each of the markers. This will help improve the performance of your application when displaying many markers.
But that is not enough. I have tried adding 2000 (1px x 1px size, 4 color) gif images as marker.icon and the result was the same. Yes, memory footprint reduced from 60MB to 54MB BUT it was still lagging as hell when you move the camera.
Google maps is a very slim framework compared to Apple maps. I have tried everything. Apple maps can handle 2000 pins and Google maps does not.
MAX_NUM_MARKER code:
int MAX_NUM_MARKER = 200;
if (IS_IPAD) {
if ([[[UIDevice currentDevice] platformString] isEqualToString:@"iPad 1G"]) {
MAX_NUM_MARKER = 150;
} else if ([[[UIDevice currentDevice] platformString] isEqualToString:@"iPad 2G"]) {
MAX_NUM_MARKER = 200;
} else if ([[[UIDevice currentDevice] platformString] isEqualToString:@"iPad 3G"]) {
MAX_NUM_MARKER = 300;
} else if ([[[UIDevice currentDevice] platformString] isEqualToString:@"iPad 4G"]) {
MAX_NUM_MARKER = 400;
} else {
MAX_NUM_MARKER = 400;
}
} else {
if (IS_IPHONE_6 || IS_IPHONE_6P) {
MAX_NUM_MARKER = 400;
} else if (IS_IPHONE_5) {
MAX_NUM_MARKER = 300;
} else if (IS_IPHONE_4_OR_LESS) {
MAX_NUM_MARKER = 150;
} else {
MAX_NUM_MARKER = 500;
}
}
is marker visible on screen code:
- (BOOL)isMarkerVisibleOnMap:(GMSMarker*)marker {
float padding = 0.0f;
CGPoint point = [map.projection pointForCoordinate:marker.position];
if (point.x >= -padding && point.y >= -padding && point.x <= map.frame.size.width+padding
&& point.y <= map.frame.size.height+padding) {
return YES;
}
return NO;
}
For Clustering we used https://github.com/googlemaps/google-maps-ios-utils found on gitHUb. Well designed, easy to use and tweak (not official) library. You basically add the markers into array once and then use "clustering" anytime the pins on map needs to be displayed.
Take a look at Apple iOS9 new map mode: SatelliteFlyover. Now thats quality + battery drain :D
Upvotes: 5
Reputation: 8429
Google Maps for iOS doesn't officially current support Marker Clustering as seen over here.
As seen over here, the are few work around you can do
Upvotes: 1