Google maps 自定义图标方向定位点颤振谷歌地图
我使用这段代码为Flutter谷歌地图标记创建一个自定义图标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
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)
有趣的是,对我来说,锚定点是底部中心。