【问题标题】:Display interactive view on marker click instead of marker info window在标记单击而不是标记信息窗口时显示交互式视图
【发布时间】:2016-08-29 21:57:03
【问题描述】:

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

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

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

【问题讨论】:

标签: ios google-maps


【解决方案1】:

可以这样做

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

谢谢

【讨论】:

  • 上述类返回一个视图,该视图被转换为图像并显示在标记点击上。我需要一个可以处理标记点击上的按钮操作的弹出视图。
猜你喜欢
  • 2018-07-28
  • 2016-07-27
  • 2013-09-02
  • 2020-07-22
  • 2013-09-18
  • 2018-10-23
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
相关资源
最近更新 更多