在Android Kotlin中将文本添加到Google Map API v2中的自定义图标

时间:2019-04-24 04:59:20

标签: android kotlin google-maps-android-api-2

我想在Google地图的自定义图标中插入文本,我已经有一个可以插入文本的工作代码,但是没有正确对齐,并且我无法确定文本的位置。还有其他方法吗?

下面是我创建的代码,我无法调整文本以使其显示在自定义图标的中心。

 val markerOptions: MarkerOptions
 val iconGen = IconGenerator(this)
 iconGen.setTextAppearance(R.style.myStyleText)

iconGen.setBackground(getResources().getDrawable(R.drawable.green))
                            markerOptions = MarkerOptions()
                                .position(LatLng(Double.parseDouble(lat_i), Double.parseDouble(long_i)))
                                .title(stationName.toString())
                                .snippet(stationAddress.toString() + "\n" + lat_i + "," + long_i))
                                .icon(BitmapDescriptorFactory.fromBitmap(iconGen.makeIcon("value inserted to image")))

这是我所做的工作的图像。 image of icon with text

0 个答案:

没有答案