在标记点击而不是标记信息窗口上显示交互式视图

时间:2016-08-29 13:24:11

标签: ios google-maps

我想显示交互式视图(按钮和文本字段)而不是标记信息窗口。 以下代码用于显示标记信息窗口。

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

如何显示交互式视图以添加按钮和文本字段,而不是点击信息窗口(didTapMarker)

1 个答案:

答案 0 :(得分:0)

可以这样做

- (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;
}

由于