我如何在Google地图上创建自己的自定义标记,例如Google地图的默认标记

问题描述 投票:0回答:1

我正在地图上添加2个自定义标记,并找到它们之间的路线。我正在从目标API获取路线,并且工作正常。但是问题是当在我的自定义标记位置上绘制此路线并绘制的折线不是100%正确时。

我正在使用此代码添加自定义标记:

MarkerOptions().position(startPos).title("Start Point") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin_start)))

MarkerOptions().position(endPos).title("End Point") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_pin_end))

但是当我使用默认标记时,一切都可以按我的要求正常工作。

MarkerOptions().position(endPos).title("End Point") .icon(BitmapDescriptorFactory.defaultMarker())

When I am adding my custom markers They are shown on the map like this从这张图片可以看出,我的圆形标记未固定到正确的位置

But actually I want like this

android google-maps kotlin google-maps-markers
1个回答
0
投票

我认为您需要使用此this method in MarkerOptions class将锚点添加到标记中>

此方法的定义

指定锚点在标记图像中的特定点。

锚点指定图标图像中锚定到地球表面标记位置的点。

例如,

将锚点设置在图标中心:
markerOptions.anchor(0.2f, 0.2f);

根据您的需要调整此锚点,它将起作用。

© www.soinside.com 2019 - 2024. All rights reserved.