简体   繁体   English

是否可以在不点击的情况下为多个标记显示多个信息窗口?

[英]Is it possible to display multiple info windows for multiple markers without tapping it?

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.创建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;
}

In the above code, 2 labels are creates priceLabel and numberOfPropertiesLabel .在上面的代码中,2 个标签创建priceLabelnumberOfPropertiesLabel The frame of both the labels are set according to your requirement ie 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.然后将此图像设置为GMSMarker图像。

You cannot select multiple markers at a time.您不能一次选择多个标记。

You can use an alternative approach instead.您可以改用另一种方法。

You can create custom markers ie, the custom marker image can be created such that it contains the information/format you want to display in the info window.您可以创建自定义标记,即可以创建自定义标记图像,使其包含您想要在信息窗口中显示的信息/格式。

The below image can give you an idea on how to achieve it:下图可以让您了解如何实现它:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS中快速显示多个标记的标记标题而不用点击它,就像iOS中照片库中的位置一样 - how to display marker title for multiple markers without tapping on it in iOS swift like places in photo gallery in iOS UITouch-是否可以禁用多次点击 - UITouch - Is it possible to disable multiple tapping 为多个标记定制信息窗口 - customizing info window for multiple markers 多个信息窗口在iOS中显示相同的文本 - Multiple info windows showing same text in iOS 如何在不点击标记的情况下在 iOS 谷歌地图中显示信息窗口? - How to show a Info window in iOS Google maps without tapping on Marker? ARToolkit多个强制标记 - ARToolkit Multiple Mandatory Markers ios谷歌地图绘制多个标记问题(信息窗口和标记重复) - ios google maps plotting multiple markers issues(info window and marker repeating) 如何使用单个标记多次点击 - how can I multiple tapping with single marker 在自定义 UITableViewCell Swift 中点击多个按钮 - Tapping Multiple Buttons in Custom UITableViewCell Swift UITapGestureRecognizer xamarin-多次轻按可快速显示多个视图 - UITapGestureRecognizer xamarin - tapping multiple times quickly displays multiple views
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM