Reputation: 3257
I am animating a marker between two points. I also drew a polyline between two points.
I want my marker to be centered on the polyline. But my custom icon is not placed at the center of the polyline as shown in the below picture.
How do I get the marker centered on the polyline?
Upvotes: 2
Views: 576
Reputation: 2452
anchor
property is what you're looking for
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)
means that your marker will be pinned at the middle of your marker image. for better understanding of this (0.0,0.0)
means left top corner of your image and (1.0,1.0) means bottom right corner. Default is (0.5,1.0)
middle of bottom edge that's why your markers looks like this.
from docs:
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).
Hope it helps :)
Upvotes: 3