1

I have a function that shared data to whatsapp number, but when sending a google location it`s not working.

when printing the URL that I get at this function: https://www.google.com/maps/search/?api=1&query=9.5191017,8.1450133

but I see that in WhatsApp look like: https://www.google.com/maps/search/?api=1

my code :

_launchURL() async {
    var phonenumber = numberphone.substring(1,10);
    var url = 'https://wa.me/+972$phonenumber?text=$textToSend';
    print(url);
    if (await canLaunch(url)) {
        await launch(url);
    } else {
        throw 'Could not launch $url';
    }
}

my code that called the _launchURL()

onPressed: () async{
    Position position = await getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
    textToSend='https://www.google.com/maps/search/?api=1&query=${position.latitude},${position.longitude}'.toString() ;   
    _launchURL();
}

any one can help me how to share location in whatsapp app using flutter ? Thank you

Sasha Kondrashov
  • 4,038
  • 1
  • 18
  • 29

1 Answers1

1

I solved this issue using the code below

final maps = Uri.https("google.com", "/maps/search/", { "api=1&query": "$lat,$lng" });
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
  • So you then put maps.toString() as textToSend? Is it possible to have a longer message, like text: "Hey my location is: \n ${maps.toString()}" – Shazamo Morebucks Jun 05 '21 at 06:00
  • Hi, I don't send it with .toString, I create a variable to send a text, like the code below: String _messageMotoBoy = "Estabelecimento: $_establishment \n\n" "Bairro: $nbHood \n" "Comp: $comp \n" "Ref: $ref \n" "Cidade: $cityUf \n\n\n" "Cobrar do Cliente: R\$ $total \n\n" "Forma de pagamento\n" "$_methodPayment" "Localização da entrega \n\n" "$waze \n\n" "$maps"; var whatsappUrl = "whatsapp://send?phone=+55${driver.phone}&text=$_messageMotoBoy"; – Tiago Bruckmann Jun 24 '21 at 12:12