import 'package:url_launcher/url_launcher.dart';
import 'package:url_launcher/url_launcher_string.dart';
class MapsUtils{
MapsUtils._();
static Future<void> openMapWithPosition(double latitude, double longitude) async{
String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$latitude,$longitude";
if(await canLaunchUrlString(googleMapUrl))
{
await launchUrlString(googleMapUrl);
}
else
{
throw "Could not open the map.";
}}
static Future<void> openMapWithAddress(String fullAddress) async {
String query = Uri.encodeComponent(fullAddress);
String googleMapUrl = "https://www.google.com/maps/search/?api=1&query=$query";
if(await canLaunchUrlString(googleMapUrl))
{
await launchUrlString(googleMapUrl);
}
else
{
throw "Could not open the map.";
} } }
**This is my code for opening maps on android using flutter. I have added all the required dependencies i.e. URL_launcher but it's not working. **
I/UrlLauncher(13043): component name for https://www.google.com/maps/search/?api=1&query=18.6446934,73.7615529 is null I/UrlLauncher(13043): component name for https://flutter.dev is null E/flutter (13043): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Could not open the map. E/flutter (13043): #0 MapsUtils.openMapWithPosition (package:user/maps/maps.dart:25:7) E/flutter (13043): E/flutter (13043):
I am getting above error