簡體   English   中英

是否可以在不點擊的情況下為多個標記顯示多個信息窗口?

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

我想在谷歌地圖中為多個標記顯示多個信息窗口。 信息窗口應該在不點擊標記本身的情況下顯示。 是否可以? 經過研究,我了解到將標記設置為地圖視圖選定標記可以使信息窗口出現而無需點擊它。 但是,不能同時選擇多個標記作為地圖視圖的選定標記。 有什么可以做的嗎?

這是創建自定義標記的代碼,如上圖所示:

創建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;
}

在上面的代碼中,2 個標簽創建priceLabelnumberOfPropertiesLabel 兩個標簽的框架都是根據您的要求設置的,即標簽在視圖中的位置。 然后根據標簽的尺寸設置視圖的框架。

然后將視圖轉換為圖像。 然后將此圖像設置為GMSMarker圖像。

您不能一次選擇多個標記。

您可以改用另一種方法。

您可以創建自定義標記,即可以創建自定義標記圖像,使其包含您想要在信息窗口中顯示的信息/格式。

下圖可以讓您了解如何實現它:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM