Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE:</strong></p> <p>Here is the code I use in order to detect tap on buttons added to my infoWindows. I create a custom infoWindow with 2 fake buttons (they could actually replaced by images because they won't trigger any action) and I add a completely transparent overlay with 2 real buttons over the infoWindow. These buttons will trigger the actions.</p> <p>And I use a few delegate methods or KVC in order to move the overlay when the infoWindow itself is moved. </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> <p><strong>FORMER POST:</strong></p> <p>Have a look at this thread and specifically at #9, should be helpful <a href="https://code.google.com/p/gmaps-api-issues/issues/detail?id=4961" rel="nofollow">https://code.google.com/p/gmaps-api-issues/issues/detail?id=4961</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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