ios - 如何在iOS中快速显示多个标记的标记标题而不点击它,就像iOS照片库中的地方一样
问题描述
我能够显示标记的信息窗口,但是我们可以在地图加载时显示信息而不用点击标记吗?
解决方案
好的,由于谷歌地图目前默认情况下不提供此功能,因此这是一种解决方法。当您创建标记时,按如下方式操作它:
首先,您创建一个视图并将标签和图像添加到其中。
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; }
我们已经将视图转换为图像,因为。它占用的内存空间较小。
希望这可以帮助。并为您提供方法的想法。
推荐阅读
- html - CSS子选择器(不能选择所有子)
- commit - 在 C# 程序中使用 SQL 提交和回滚的正确方法是什么
- android-studio - 为什么以前的打印语句会出现在新项目构建控制台中 - android studio/flutter
- java - 通过 Scanner.nextFloat() 读取浮点数时出现 InputMismatchException
- excel - 页边距在 mlreportgen 报告中交替变化
- sql-server - SQL Server 组件约束或多于 1 列的约束
- python - 在 Django 目录中执行 .py 文件
- c# - 使用点表示法在函数中封装和使用 LINQ 逻辑
- ruby-on-rails - logstash - 使用 Ruby 过滤器从日志中解析数字并转换存储单元
- javascript - 文档未在 node.js 上定义 - 如何将变量从另一个 .js 文件导入 node.js 服务器?