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

和自甴很熟 提交于 2019-11-30 20:50:02

问题


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?


回答1:


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.




回答2:


You cannot select multiple markers at a time.

You can use an alternative approach instead.

You can create custom markers i.e., 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:



来源:https://stackoverflow.com/questions/39487733/is-it-possible-to-display-multiple-info-windows-for-multiple-markers-without-tap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!