繁体   English   中英

如何在iOS中快速显示多个标记的标记标题而不用点击它,就像iOS中照片库中的位置一样

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

我无法显示标记的信息窗口,但是在加载地图时无需点击标记就可以显示信息吗?

好的,由于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; } 

我们之所以将视图转换为图像,是因为。 它占用较少的内存空间。

希望这可以帮助。 并为您提供了一种方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM