Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This code does exactly what you want. It's inspired by #9 in the <a href="https://code.google.com/p/gmaps-api-issues/issues/detail?id=4961" rel="noreferrer">link</a> recommended by Saxon Druce but done differently and more complete. It detects tap on buttons added to my custom infoWindow. I create a custom infoWindow with 2 fake buttons (they could actually be replaced by images because they won't trigger any action anyway) and I add a transparent UIView with 2 real but transparent buttons over the infoWindow. These buttons will trigger the actions.</p> <p>Finally, I use a few delegate methods or KVC in order to move the overlaid UIView when the infoWindow itself moves. </p> <pre><code>- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker { [self.actionOverlayCalloutView removeFromSuperview]; UIView *calloutView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, infoWindowWidth, infoWindowHeight)]; float offset = anchorSize * M_SQRT2; CGAffineTransform rotateBy45Degrees = CGAffineTransformMakeRotation(M_PI_4); UIView *arrow = [[UIView alloc] initWithFrame:CGRectMake((infoWindowWidth - anchorSize)/2.0, infoWindowHeight - offset, anchorSize, anchorSize)]; arrow.transform = rotateBy45Degrees; arrow.backgroundColor = [UIColor lightGrayColor]; [calloutView addSubview:arrow]; UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, infoWindowWidth, infoWindowHeight - offset/2)]; [contentView setBackgroundColor:[UIColor whiteColor]]; contentView.layer.cornerRadius = 5; contentView.layer.masksToBounds = YES; contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; contentView.layer.borderWidth = 1.0f; self.actionOverlayCalloutView = [NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:contentView]]; //hack to copy a view... self.actionOverlayCalloutView.backgroundColor = [UIColor lightGrayColorWithAlpha:0.5]; self.actionOverlayCalloutView.layer.cornerRadius = 5; NSMutableArray *falseButtons = [NSMutableArray array]; NSMutableArray *actionButtons = [NSMutableArray array]; PointMapItem *pointAnnotation = marker.userData; if ([pointAnnotation canPerformSend]) { UIButton *button = [[UIButton alloc] init]; [button setImage:[UIImage imageNamed:@"imageButton1.png"] forState:UIControlStateNormal]; [falseButtons addObject:button]; UIButton *activableButton = [[UIButton alloc] init]; [activableButton addTarget:self action:@selector(onButton1Clicked) forControlEvents:UIControlEventTouchUpInside]; [actionButtons addObject:activableButton]; } if ([pointAnnotation canPerformShowDetails]) { UIButton *button = [[UIButton alloc] init]; [button setImage:[UIImage imageNamed:@"imageButton1.png"] forState:UIControlStateNormal]; [falseButtons addObject:button]; UIButton *activableButton = [[UIButton alloc] init]; [activableButton addTarget:self action:@selector(onButton2Clicked) forControlEvents:UIControlEventTouchUpInside]; [actionButtons addObject:activableButton]; } int buttonWidth = contentView.frame.size.width / [falseButtons count]; int currentOffset = 0; for (int i=0; i&lt;falseButtons.count; i++) { UIButton *falseButton = [falseButtons objectAtIndex:i]; UIButton *activableButton = [actionButtons objectAtIndex:i]; [falseButton setFrame:CGRectMake(currentOffset, 0, buttonWidth, contentView.frame.size.height)]; currentOffset += buttonWidth; activableButton.frame = falseButton.frame; [activableButton setTitle:@"" forState:UIControlStateNormal]; [self.actionOverlayCalloutView addSubview:activableButton]; [contentView addSubview:falseButton]; } [calloutView addSubview:contentView]; CLLocationCoordinate2D anchor = [self.mapView.selectedMarker position]; CGPoint point = [self.mapView.projection pointForCoordinate:anchor]; point.y -= self.mapView.selectedMarker.icon.size.height + offset/2 + (infoWindowHeight - offset/2)/2; self.actionOverlayCalloutView.center = point; [self.mapView addSubview:self.actionOverlayCalloutView]; return calloutView; } - (void)mapView:(GMSMapView *)pMapView didChangeCameraPosition:(GMSCameraPosition *)position { if (pMapView.selectedMarker != nil &amp;&amp; self.actionOverlayCalloutView.superview) { CLLocationCoordinate2D anchor = [self.mapView.selectedMarker position]; CGPoint point = [self.mapView.projection pointForCoordinate:anchor]; float offset = anchorSize * M_SQRT2; point.y -= self.mapView.selectedMarker.icon.size.height + offset/2 + (infoWindowHeight - offset/2)/2; self.actionOverlayCalloutView.center = point; } else { [self.actionOverlayCalloutView removeFromSuperview]; } } - (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate { [self.actionOverlayCalloutView removeFromSuperview]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"mapView.selectedMarker"]) { if (!self.mapView.selectedMarker) { [self.actionOverlayCalloutView removeFromSuperview]; } } } - (void)onButton2Clicked { //your code self.mapView.selectedMarker = nil; } - (void)onButton1Clicked { // your code; self.mapView.selectedMarker = nil; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload