0

I want to display interactive view(buttons and textfields) instead of marker info window. The following code is used to display marker info window.

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
 // created customized view
}

How can i display interactive view to add buttons and textfields instead of tapping info window (didTapMarker)

User
  • 1
  • 1
  • Welcome to Stack Overflow! Please take the [tour](http://stackoverflow.com/tour), have a look around, and read through the [help center](http://stackoverflow.com/help), in particular [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – Squazz Aug 29 '16 at 13:32
  • Check this SO question [19490619](http://stackoverflow.com/questions/19490619/adding-uitextfield-and-uibutton-on-google-map) and [16497648](http://stackoverflow.com/questions/16497648/google-maps-ios-sdk-add-uiview-uibutton-over-a-gmsmapview) if it can help you. – KENdi Aug 30 '16 at 10:37

1 Answers1

0

Can do like this

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
UIView *v = [UIView new];
v.frame = CGRectMake(0, 0, 230, 80);
v.backgroundColor = [UIColor whiteColor];
v.layer.borderColor = [UIColor blackColor].CGColor;
v.layer.borderWidth = 1.0f;
v.layer.cornerRadius = 20.f;

NSString *imageURL = nil;
NSString *address = nil;
NSString *name = nil;
if ([marker.userData isKindOfClass:[DemoLocation class]]) //DemoLocation your modelObject
{
    DemoLocation *location = marker.userData;
    NSArray *array = [location.address componentsSeparatedByString:@"\n"];
    if (array.count >= 1)
    {
        name = array[0];
    }

    if (array.count >= 2)
    {
        address = array[1];
    }
}
else if([marker.userData isKindOfClass:[GooglePlace class]])
{
    GooglePlace *place = marker.userData;
    imageURL = place.iconURL;
    name = place.name;
    address = place.vicinity;
}

if (imageURL)
{
    UIImageView *imageView = [UIImageView new];
    [imageView sd_setImageWithURL:[NSURL URLWithString:imageURL]];
    [v addSubview:imageView];
    imageView.frame = CGRectMake(10, 25, 40, 40);
}

UILabel *titleLabel = [UILabel new];
titleLabel.font = [StyleHelper createBoldFontWithSize:FONTSIZE_M]; //StyleHelper custom class  
titleLabel.text = name;
titleLabel.numberOfLines = 1;
titleLabel.adjustsFontSizeToFitWidth = YES;
titleLabel.minimumScaleFactor = 0.5f;
[v addSubview:titleLabel];
titleLabel.frame = CGRectMake(55, 5, 170, 16);
[titleLabel sizeToFit];

UILabel *addressLabel = [UILabel new];
addressLabel.font = [StyleHelper createFontWithSize:FONTSIZE_M];
addressLabel.text = address;
addressLabel.numberOfLines = 2;
addressLabel.adjustsFontSizeToFitWidth = YES;
addressLabel.minimumScaleFactor = 0.8f;
[v addSubview:addressLabel];
addressLabel.frame = CGRectMake(55, 24, 170, 26);
[addressLabel sizeToFit];

UILabel *label = [UILabel new];
label.textAlignment = NSTextAlignmentCenter;
label.font = [StyleHelper createBoldFontWithSize:FONTSIZE_M];
label.text = @"Click to play here!";
label.frame = CGRectMake(55, 64, 170, 14);
[v addSubview:label];

return v;
}

Thanks

Andolasoft Inc
  • 1,296
  • 1
  • 7
  • 16
  • Above class returns a view which is converted into image and displayed on marker tap.I need a popup view which can handle button actions on marker tap. – User Aug 30 '16 at 04:35