折线上的居中标记

Centered marker on polyline

我正在为两点之间的标记设置动画。我还在两点之间画了一条折线。

我希望我的标记以多段线为中心。但是我的自定义图标没有放在折线的中心,如下图所示。

如何让标记以折线为中心?

anchor 属性 就是您要找的

static final LatLng PERTH = new LatLng(-31.90, 115.86);
Marker perth = mMap.addMarker(new MarkerOptions()
                      .position(PERTH)
                      .anchor(0.5,0.5))

(0.5,0,5) 表示您的标记将固定在标记图像的中间。为了更好地理解这个 (0.0,0.0) 表示图像的左上角,而 (1.0,1.0) 表示右下角。默认是底边的 (0.5,1.0) 中间,这就是你的标记看起来像这样的原因。

来自文档:

The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).

source

希望对您有所帮助:)