0
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

  • Does this answer your question? [I/UrlLauncher(17669): component name for (url) is null](https://stackoverflow.com/questions/70224911/i-urllauncher17669-component-name-for-url-is-null) – user18309290 Aug 04 '22 at 15:13

1 Answers1

0

From android 11 (API 30) and above, you must add QUERY_ALL_PACKAGES permission to AndroidManifest.xml

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

refer to the following link for more information: https://developer.android.com/training/package-visibility/declaring

Tharindu Lakshan
  • 3,995
  • 6
  • 24
  • 44