Flutter Want to navigate to google maps

Issue

I have a set of locations. Starting point > Mid Point > Ending Point.
I want to create a button in which when the user presses the button it will redirect the user to the actual google maps direction and it should set the direction automatically on google maps.
how can I make it work?

Solution

use url_launcher package and set latitudeopen and longitude of origin and destination location, then open this url

https://maps.google.com/maps?saddr=currentLatitude,currentLongitude&daddr=destLatitude,destLongitude

Url example :

http://maps.google.com/maps?saddr=41.3999625,2.1958264&daddr=41.3942644,2.1885308

example:

import 'package:url_launcher/url_launcher.dart';
...    
GestureDetector(
       onTap: ()=> launch('http://maps.google.com/maps?saddr=41.3999625,2.1958264&daddr=41.3942644,2.1885308'),
       child: Text('open map'),
    )
...

Answered By – Mehdi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published