launchMapsApp function

Future<void> launchMapsApp({
  1. required String latitude,
  2. required String longitude,
  3. String label = '',
})

Implementation

Future<void> launchMapsApp({
  required String latitude,
  required String longitude,
  String label = '',
}) async {
  if (latitude.isEmpty || longitude.isEmpty) {
    return;
  }

  final Uri googleMapUri = Uri.parse(
    'https://www.google.com/maps/search/?api=1&query=$latitude,$longitude${label.isNotEmpty ? '($label)' : ''}',
  );

  if (await canLaunchUrl(googleMapUri)) {
    await launchUrl(googleMapUri, mode: LaunchMode.externalApplication);
  } else {
    throw 'Impossible de lancer Google Maps';
  }
}