【问题标题】:Is it possible to display multiple info windows for multiple markers without tapping it?是否可以在不点击的情况下为多个标记显示多个信息窗口?
【发布时间】:2017-01-22 02:24:06
【问题描述】:

我想在谷歌地图中显示多个标记的多个信息窗口。信息窗口应在不点击标记本身的情况下显示。可能吗?经过研究,我了解到将标记设置为地图视图选择标记可以使信息窗口出现而无需点击它。但是,不能一次选择多个标记作为地图视图的选定标记。有什么可以做的吗?

【问题讨论】:

    标签: ios swift google-maps google-maps-markers


    【解决方案1】:

    这是创建自定义标记的代码,如上图所示:

    创建UIView 的子类并将以下方法添加到该类中。

    -(UIImage*)createCustomMarkerImageWithMarker:(GMSMarker *)marker
    {
        CGRect priceLabelRect = [marker.title boundingRectWithSize:CGSizeMake(500, 50)
                                                           options:NSStringDrawingUsesLineFragmentOrigin
                                                        attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]}
                                                           context:nil];
    
        UILabel *priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, priceLabelRect.size.width+25, priceLabelRect.size.height+12)];
        priceLabel.text = [NSString stringWithFormat:@" ₹ %@ ",marker.title];
        priceLabel.textAlignment = NSTextAlignmentCenter;
        priceLabel.textColor = [UIColor blackColor];
        priceLabel.backgroundColor = [UIColor clearColor];
        priceLabel.font = [UIFont systemFontOfSize:11];
    
    
    
        CGRect numberOfPropertiesLabelRect = [marker.snippet boundingRectWithSize:CGSizeMake(300, 50)
                                                                          options:NSStringDrawingUsesLineFragmentOrigin
                                                                       attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10]}
                                                                          context:nil];
        UILabel *numberOfPropertiesLabel = [[UILabel alloc]initWithFrame:CGRectMake(priceLabel.frame.size.width, 0, numberOfPropertiesLabelRect.size.width+10, numberOfPropertiesLabelRect.size.height+12)];
        numberOfPropertiesLabel.text = marker.snippet;
        numberOfPropertiesLabel.textAlignment = NSTextAlignmentCenter;
        numberOfPropertiesLabel.textColor = [UIColor whiteColor];
        numberOfPropertiesLabel.backgroundColor = [UIColor clearColor];
        numberOfPropertiesLabel.font = [UIFont systemFontOfSize:11];
    
        self.frame = CGRectMake(0, 0, priceLabel.frame.size.width+numberOfPropertiesLabel.frame.size.width, priceLabel.frame.size.height+TriangleHeight);
    
        [self addSubview:priceLabel];
        [self addSubview:numberOfPropertiesLabel];
    
    
        UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, [[UIScreen mainScreen] scale]);
        [self.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage * icon = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    
        return icon;
    }
    

    在上面的代码中,两个标签是创建priceLabelnumberOfPropertiesLabel。两个标签的框架都是根据您的要求设置的,即标签在视图中的位置。然后根据标签的尺寸设置视图的框架。

    然后视图被转换为图像。然后将此图像设置为GMSMarker 图像。

    【讨论】:

      【解决方案2】:

      您不能一次选择多个标记。

      您可以改用其他方法。

      您可以创建自定义标记,即可以创建自定义标记图像,使其包含您要在信息窗口中显示的信息/格式。

      下图可以让您了解如何实现它:

      【讨论】:

      猜你喜欢
      • 2013-03-26
      • 2012-02-17
      • 1970-01-01
      • 2014-07-12
      • 2019-09-02
      • 2017-08-21
      • 1970-01-01
      • 2013-08-15
      相关资源
      最近更新 更多