fitCameraToLatLngs method

Future<CommandCompletion> fitCameraToLatLngs(
  1. List<LatLng> coordinates,
  2. CameraFitUpdate update
)

Moves the camera to fit coordinates in the map's view, at once or with an animation.

coordinates must not be empty. The camera is the one that MapHandle.cameraForLatLngs() computes after the commands sent before this one apply. The function finishes when the map applies the change, before an animation ends.

See mln_map_fit_camera_to_lat_lngs in the C API reference.

Errors:

  • Status.invalidArgument when the padding in update leaves no room for the area. The camera doesn't move.

Implementation

Future<CommandCompletion> fitCameraToLatLngs(
  List<LatLng> coordinates,
  CameraFitUpdate update,
) => _command((arena, completion) {
  final nativecoordinates = arena<raw.mln_lat_lng>(
    coordinates.isEmpty ? 1 : coordinates.length,
  );
  for (var index = 0; index < coordinates.length; index++) {
    _writeLatLng(coordinates[index], arena, into: nativecoordinates + index);
  }
  final registrations = _NativeRegistrations(_callbackRoots);
  return registrations.run(
    () => raw.mln_map_fit_camera_to_lat_lngs(
      _handle.raw,
      nativecoordinates,
      coordinates.length,
      _writeCameraFitUpdate(update, arena, registrations),
      completion,
      nativeDiagnostic,
    ),
  );
});