getCurrentLocation method

Future<LatLng?> getCurrentLocation()

Returns the current device position as a one-shot request.

Useful for "My Location" button or initial positioning.

Implementation

Future<LatLng?> getCurrentLocation() async {
  final hasPermission = await requestPermission();
  if (!hasPermission) return null;

  try {
    final position = await Geolocator.getCurrentPosition(
      locationSettings: const LocationSettings(
        accuracy: LocationAccuracy.high,
        timeLimit: Duration(seconds: 10),
      ),
    );
    _lastPosition = position;
    positionNotifier.value = position;
    return LatLng(position.latitude, position.longitude);
  } catch (e) {
    debugPrint('PowerMap Tracking: Failed to get current location: $e');
    return null;
  }
}