是否可以显示多个标记的多个信息窗口而不用点击它? [英] Is it possible to display multiple info windows for multiple markers without tapping it?

查看:78
本文介绍了是否可以显示多个标记的多个信息窗口而不用点击它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

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



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

$ $ p $ - (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();

返回图标;



$ b $ p
$ b

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

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


I want to display multiple info window for multiple markers in google map. The info window should display without tapping the marker itself. Is it possible? After researching, I learned that setting the marker as mapview selected marker can make the info window appear without tapping it. However, multiple markers cannot be selected as the selected marker of the mapview at a time. Is there anything that can be done?

解决方案

Here is the code to create custom markers as shown in the above image:

Create a subclass of UIView and add the below method to the class.

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

In the above code, 2 labels are creates priceLabel and numberOfPropertiesLabel. The frame of both the labels are set according to your requirement i.e. the position of the labels in the view. Then the frame of the view is set according to the labels' dimensions.

View is then converted into an image. This image is then set as the GMSMarker image.

这篇关于是否可以显示多个标记的多个信息窗口而不用点击它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆