google-maps-ios-utils
google-maps-ios-utils copied to clipboard
How to differenciate cluster from spot in mapView:didTapMarker: ?
I'm trying to do 2 different thing with this method. I'd like to zoom in if I tap on a cluster and display an alert if I tap on a spot, how can I do that?
+1, I'm interested too.
@CptMedo and @Chiliec : Subclass the GMSMarker and have two properties in it. Like below
@interface CustomGMSMarker : GMSMarker
@property (nonatomic) NSInteger count;
@property (nonatomic, strong) NSArray *markerArray;
@end
In GDefaultClusterRenderer class change the method - (void)clustersChanged:(NSSet*)clusters as below.
- (void)clustersChanged:(NSSet*)clusters {
for (GMSMarker *marker in _markerCache) {
marker.map = nil;
}
[_markerCache removeAllObjects];
for (id <GCluster> cluster in clusters) {
ClusterMarker *marker;
marker = [[ClusterMarker alloc] init];
[_markerCache addObject:marker];
NSUInteger count = cluster.items.count;
marker.count = count;
marker.markerArray = [cluster.items valueForKey:@"marker"];
if (count > 1) {
marker.icon = [self generateClusterIconWithCount:count];
}
else {
marker.icon = cluster.marker.icon;
}
marker.userData = cluster.marker.userData;
marker.position = cluster.marker.position;
marker.map = _map;
}
}
And in your GMSMapViewDelegate method you will receive the custom marker, you can type cast and use it.
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker.