initialize static method

Future<void> initialize({
  1. required LocationConfig config,
})

Initializes the plugin with the given configuration.

This must be called exactly once before using any other methods.

Throws LocationAlreadyInitializedException if already initialized. Throws LocationInitializationException on platform errors. Throws LocationConfigurationException if config is invalid.

Implementation

static Future<void> initialize({required LocationConfig config}) async {
  if (_instance != null) {
    throw LocationAlreadyInitializedException(
      message:
          'LiveLocation already initialized. Call dispose() first to '
          're-initialize with different config.',
    );
  }

  try {
    _instance = LiveLocation._internal(config);
    await _instance!._initializePlatform();
  } catch (e) {
    _instance = null;
    if (e is LocationException) {
      rethrow;
    }
    throw LocationInitializationException(
      message: 'Initialization failed: $e',
    );
  }
}