如何在 iOS swift 中显示多个标记的标记标题而无需点击它,就像 iOS 中照片库中的地方一样

how to display marker title for multiple markers without tapping on it in iOS swift like places in photo gallery in iOS

我能够显示标记的信息 window,但是我们可以在加载地图时甚至不点击标记就显示信息吗?

好的,因为 google 地图目前默认不提供此功能,这里是一个解决方法。当您创建标记时,按如下方式操作它:

  • 首先创建一个视图并向其中添加标签和图像。

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
            // Set label properties as required including marker Name
    
    UIImageView *markerIconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(35, 10, 30, 50)];
            // Set image properties as required including image which will be displayed as marker
    
    UIView *markerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    [markerView addSubview:label];
    [markerView addSubview:markerIconImageView];
    
  • 然后创建一个标记并将其指定为上面视图的图像:

    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.icon  = [self imageWithView:markerView];
    marker.position = coordinates for marker;
    marker.appearAnimation = kGMSMarkerAnimationPop;
    marker.map = your map;
    
  • 这里是我将视图转换为图像的函数供参考:

    -(UIImage *) imageWithView:(UIView *)view
    {
        UIGraphicsBeginImageContext(view.bounds.size);
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
     }
    

我们已将视图转换为图像,因为。它占用的内存较少space。

希望这对您有所帮助。并为您提供有关该方法的想法。