iSuresh iSuresh - 2 years ago 180
Objective-C Question

Button on Custom info Window not Receiving Action in ios

I am using Google Maps in iOS Application and have implemented a custom info window for showing title of a marker.

Now, I added a button on that custom info window but my problem is that the button action method does not get called.


#import <UIKit/UIKit.h>

@interface CustomInfoWindow : UIView
@property (nonatomic,weak) IBOutlet UILabel *addressLabel;
@property(nonatomic) IBOutlet UIButton *button;

and in
, I have added

  • UILabel

  • UIButton


#import "CustomInfoWindow.h"

@interface viewController : UIViewController<GMSMapViewDelegate>
GMSMapView *mapView;


- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
NSLog(@"Mrker Tapped");

CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"infoWindow"
options:nil] objectAtIndex:0];
infoWindow.addressLabel.text = marker.title;

[infoWindow.button addTarget:self action:@selector(ButtonPressed)
return infoWindow;

NSLog(@"Button Pressed");

method does not fire.

Answer Source

I haven't used Google Maps SDK but after following a few links, it seems what you're trying to accomplish may not be easy.

PS: This maybe Android documentation but it seems it holds true for iOS as well.

To quote:

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

You could instead implement GMSMapViewDelegate's -didTapInfoWindowOfMarker: delegate method to check if the infowindow was tapped.
(the drawback is that the entire infowindow becomes one button)

Other links:

similar question 1
similar question 2

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download