首页 > 解决方案 > 如何在iOS中快速显示多个标记的标记标题而不点击它,就像iOS照片库中的地方一样

问题描述

我能够显示标记的信息窗口,但是我们可以在地图加载时显示信息而不用点击标记吗?

标签: iosdictionarymarker

解决方案


好的,由于谷歌地图目前默认情况下不提供此功能,因此这是一种解决方法。当您创建标记时,按如下方式操作它:

  • 首先,您创建一个视图并将标签和图像添加到其中。

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

我们已经将视图转换为图像,因为。它占用的内存空间较小。

希望这可以帮助。并为您提供方法的想法。


推荐阅读