Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - Open Location in Maps

Given lat and long. Is there any fast/smart way to open maps google/apple in Flutter and head to directions ?

I'm using url_launcher for telephone calls, can i use the plugin to open link that open maps ?

_launchURL() async {
  const url = 'https://www.google.com/maps/place/Al+qi,+ADoqi,+Giza+Governorate/@33.0523046,38.2009323,17z/data=!3m1!4b1!4m5!3m4!1s0x1458413a996ec217:0x2411f6b62d93ccc!8m2!3d30.05237!4d31.2031598';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}
like image 584
mustafabarakat Avatar asked Sep 30 '18 12:09

mustafabarakat


People also ask

How do you open the location in Flutter?

To show the location popup within the app, you can use location package in your Project. Add this package by adding the following lines in your pubspec. yaml file. This code will show the following alert dialog within App.


1 Answers

Yes you can do that using the url_launcher plugin. The following code will open Google Maps when the app is installed on the phone (otherwise it will open the browser):

void _launchMapsUrl(double lat, double lon) async {
  final url = 'https://www.google.com/maps/search/?api=1&query=$lat,$lon';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}
like image 52
Frederik Schweiger Avatar answered Sep 18 '22 06:09

Frederik Schweiger