// service/maps_launcher_service.dart import 'dart:io' show Platform; import 'package:android_intent_plus/android_intent.dart'; class MapsLauncherService { /// Opens a URL in Google Maps app /// Falls back to browser if Maps app is not installed static Future openInGoogleMaps(String url) async { if (!Platform.isAndroid) { // Handle iOS or other platforms if needed return false; } try { // Try to open in Google Maps app final intent = AndroidIntent( action: 'action_view', data: url, package: 'com.google.android.apps.maps', ); await intent.launch(); return true; } catch (e) { // Google Maps not installed, try browser as fallback try { final browserIntent = AndroidIntent(action: 'action_view', data: url); await browserIntent.launch(); return true; } catch (e) { print('Failed to open maps link: $e'); return false; } } } /// Opens navigation to specific coordinates static Future navigateToCoordinates( String latitude, String longitude, ) async { final url = 'google.navigation:q=$latitude,$longitude'; return openInGoogleMaps(url); } /// Opens a search query in Google Maps static Future searchInMaps(String query) async { final encodedQuery = Uri.encodeComponent(query); final url = 'geo:0,0?q=$encodedQuery'; return openInGoogleMaps(url); } /// Shares a Google Maps link or location via Android share sheet static Future shareLocation({ required String text, String? subject, }) async { if (!Platform.isAndroid) { return false; } try { final intent = AndroidIntent( action: 'action_send', type: 'text/plain', arguments: { 'android.intent.extra.TEXT': text, if (subject != null) 'android.intent.extra.SUBJECT': subject, }, ); await intent.launch(); return true; } catch (e) { print('Failed to share location: $e'); return false; } } }