Issue
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';
}
}
Solution
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';
}
}
Answered By - Frederik Schweiger
Answer Checked By - Senaida (JavaFixing Volunteer)