navigateTo static method

Future<void> navigateTo({
  1. required double targetLatitude,
  2. required double targetLongitude,
})

Static method to navigate to a target location

Implementation

static Future<void> navigateTo({
  required double targetLatitude,
  required double targetLongitude,
}) async {
  try {
    final isGoogleMapsAvailable =
        await MapLauncher.isMapAvailable(MapType.google) ?? false;
    final isAppleMapsAvailable =
        await MapLauncher.isMapAvailable(MapType.apple) ?? false;
    if (Platform.isIOS) {
      if (isGoogleMapsAvailable && isAppleMapsAvailable) {
        await _showAppSelectionDialog(
          context: Get.context!,
          targetLatitude: targetLatitude,
          targetLongitude: targetLongitude,
        );
      } else if (isGoogleMapsAvailable) {
        await MapLauncher.showDirections(
          mapType: MapType.google,
          destination: Coords(
            targetLatitude,
            targetLongitude,
          ),
        );
      } else if (isAppleMapsAvailable) {
        await MapLauncher.showDirections(
          mapType: MapType.apple,
          destination: Coords(
            targetLatitude,
            targetLongitude,
          ),
        );
      } else {
        throw 'Neither Google Maps nor Apple Maps is available.';
      }
    } else if (Platform.isAndroid) {
      final isGoogleMapsAvailableAndroid =
          await MapLauncher.isMapAvailable(MapType.google) ?? false;
      if (isGoogleMapsAvailableAndroid) {
        await MapLauncher.showDirections(
          mapType: MapType.google,
          destination: Coords(
            targetLatitude,
            targetLongitude,
          ),
        );
      } else {
        throw 'Google Maps is not available on this device.';
      }
    }
  } catch (e) {
    // Handle errors
    throw Exception('Error: $e');
  }
}