自定义图标方向锚点 Flutter Google 地图

TSR*_*TSR 2 google-maps flutter

我使用此代码为 Flutter Google 地图标记创建自定义图标

createMarker(){
    final MarkerId markerId = getMarkerId();
      markers[markerId] = Marker(
        rotation: driverLocation.orientation,
        markerId: markerId,
        icon: BitmapDescriptor.fromBytes(await getBytesFromAsset('assets/icons/taxi-icon.png', 50);),
        position: position.toLatLng(),
      );
}
 Future<Uint8List> getBytesFromAsset(String path, int width) async {
    ByteData data = await rootBundle.load(path);
    ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), targetWidth: width);
    ui.FrameInfo fi = await codec.getNextFrame();
    return (await fi.image.toByteData(format: ui.ImageByteFormat.png)).buffer.asUint8List();
  }
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我调整了方向,我发现标记的锚点似乎位于图像的顶部边缘,而不是在其中心。如何将锚点更改为图像的中心?

Pro*_*hit 5

尝试向标记添加锚参数。

Marker(
   ...
   anchor: const Offset(0.5, 0.5)
);
Run Code Online (Sandbox Code Playgroud)

默认:

anchor: const Offset(0.5, 1.0)
Run Code Online (Sandbox Code Playgroud)

要将锚点设置为图标的中心:

anchor: const Offset(0.5, 0.5)
Run Code Online (Sandbox Code Playgroud)

要将锚点设置为图标的左上角:

anchor: const Offset(0.0, 0.0)
Run Code Online (Sandbox Code Playgroud)

要将锚点设置到图标的右下角:

anchor: const Offset(1.0, 1.0)
Run Code Online (Sandbox Code Playgroud)