Android API有一个非常方便的类IconGenerator
。使用我的Android应用程序中的IconGenerator
,我可以轻松地制作一个标记:
1.是一个简单的长方形,颜色由我选择。
1.调整大小以容纳任意长度的文本。
1.是不是**一个信息窗口-我想标记本身包含的文本,如下面的图片所示,从Android版本。
// Android - problem solved with IconGenerator
IconGenerator iconGenerator = new IconGenerator(context);
iconGenerator.setStyle(IconGenerator.STYLE_GREEN); // or any other color
Bitmap iconBitmap = iconGenerator.makeIcon(myString);
Marker m = new MarkerOptions().icon(BitmapDescriptorFactory.fromBitmap(iconBitmap))
.position(myLatLng);
map.addMarker(m); // map is a com.google.android.gms.maps.GoogleMap
有没有一种方法可以在iOS中使用Swift来做这样简单的事情?iOS API中有一个recent release,允许“标记自定义”,但我不知道如何将其应用到这个用例中。
// iOS (Swift) - I don't know how to create the icon as in code above
let marker = GMSMarker(position: myLatLng)
marker.icon = // How can I set to a rectangle with color/text of my choosing?
marker.map = map // map is a GMSMapView
9条答案
按热度按时间kxe2p93d1#
以下是我所做的
输出为
我的标记图像是
你可以根据你的需要改变你的颜色。如果你想要一些矩形的东西,你可以只创建一个简单的小矩形图像,并像我上面做的那样使用它,改变你需要的颜色。
或者,如果你想要一个包含文本的矩形,你可以只创建一个带有一些标签的小
UIView
,然后将UIView
转换为UIImage
,并可以做同样的事情。希望对你有帮助!!
8wigbo562#
这是我所做的解决同样的问题,你所面临的。
我在我的图片资产中添加了下面的图片,
现在我在代码中添加了下面的方法:
现在,我调用了这个方法,同时将icon分配给GMSMarker,如下所示:
它将生成如下所示的图像图标:
在这里,我保持了背景图像的大小固定,因为我需要。您仍然可以自定义它来调整它根据文本大小,以及多行。
更新
Swift中的代码更新:
huwehgph3#
您可以简单地在GoogleMap中添加自定义视图作为标记。
您可以使用imageView(用于包含橙子框)和它上面的label(用于文本)
ki0zmccv4#
我试着重写了Mehul Thakkar对Swift 3的回答。希望它能为你工作。但正如Dari所说的那样,定制视图真的很容易。
aij0ehis5#
这里有一个Swift 5版本的Eridana的Swift转换的Mehul Thakkar的答案。
cunj1qz16#
最简单的方法来实现,如果你只有一个图像:
1)在最新的XCode中写入
marker.icon = "imageLiteral"
。2)双击刚才出现的虚拟图像图标。
3)选择所需的图像。
yhqotfr87#
mspsb9vt8#
简单和最简单的方法来改变图标.只需替换这些3图标(默认marker.png)到您的图标(1x,2x,3x).
在Google Cluster中,标记(图标)更改存在问题。
lnvxswe29#
这就是我如何实现它,完全是程序化的:
函数调用:
结果: