[英]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 个标签创建
priceLabel
和numberOfPropertiesLabel
。 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.