简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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