简体   繁体   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

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

Okay, since google maps currently don't provide this functionality by default here is a work around. 好的,由于Google地图当前默认不提供此功能,因此可以解决此问题。 When you create your marker manipulate it as follows: 创建标记时,请按以下步骤进行操作:

  • First you create a view and add your label and image to it. 首先,您创建一个视图并向其中添加标签和图像。

     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]; 
  • Then you create a marker and assign it the image of above view: 然后创建一个标记,并为其分配上方视图的图像:

     GMSMarker *marker = [[GMSMarker alloc] init]; marker.icon = [self imageWithView:markerView]; marker.position = coordinates for marker; marker.appearAnimation = kGMSMarkerAnimationPop; marker.map = your map; 
  • For reference here is my function for converting view to image: 供参考,这是我将视图转换为图像的功能:

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

We have converted the view to image because. 我们之所以将视图转换为图像,是因为。 It takes up lesser space in memory. 它占用较少的内存空间。

Hope this helps. 希望这可以帮助。 And gives you an idea for the approach. 并为您提供了一种方法。

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

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