Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps 自定义图标方向定位点颤振谷歌地图_Google Maps_Flutter - Fatal编程技术网

Google maps 自定义图标方向定位点颤振谷歌地图

Google maps 自定义图标方向定位点颤振谷歌地图,google-maps,flutter,Google Maps,Flutter,我使用这段代码为Flutter谷歌地图标记创建一个自定义图标 createMarker(){ final MarkerId markerId = getMarkerId(); markers[markerId] = Marker( rotation: driverLocation.orientation, markerId: markerId, icon: BitmapDescriptor.fromBytes(await get

我使用这段代码为Flutter谷歌地图标记创建一个自定义图标

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();
  }
createMarker(){
final MarkerId MarkerId=getMarkerId();
markers[markerId]=标记器(
旋转:驱动器位置。方向,
马克里德:马克里德,
icon:BitmapDescriptor.fromBytes(等待getBytesFromAsset('assets/icons/taxi icon.png',50);),
位置:position.tolatng(),
);
}
未来getBytesFromAsset(字符串路径,整型宽度)异步{
ByteData data=等待rootBundle.load(路径);
ui.Codec Codec=wait ui.instantialeimagecodec(data.buffer.asUint8List(),targetWidth:width);
ui.FrameInfo fi=await codec.getNextFrame();
return(wait fi.image.toByteData(格式:ui.ImageByteFormat.png)).buffer.asUint8List();
}

它工作得很好,但我对方向进行了调整,我发现标记的定位点似乎位于图像的上边缘,而不是其中心。如何将定位点更改为图像的中心?

尝试向标记添加定位参数

Marker(
   ...
   anchor: const Offset(0.5, 0.5)
);
默认值:

anchor: const Offset(0.5, 1.0)
要将定位点设置为图标的中心,请执行以下操作:

anchor: const Offset(0.5, 0.5)
anchor: const Offset(0.0, 0.0)
anchor: const Offset(1.0, 1.0)
要将定位点设置到图标的左上角,请执行以下操作:

anchor: const Offset(0.5, 0.5)
anchor: const Offset(0.0, 0.0)
anchor: const Offset(1.0, 1.0)
要将定位点设置到图标的右下角,请执行以下操作:

anchor: const Offset(0.5, 0.5)
anchor: const Offset(0.0, 0.0)
anchor: const Offset(1.0, 1.0)

有趣的是,对我来说,锚定点是底部中心。