Reputation: 21
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
Upvotes: 2
Views: 1567
Reputation: 79
Try this
String locationUrl =
'https://www.google.com/maps/search/?
api=1&query=${latitude},${longitude}';
String whatsappUrl = Uri.parse('https://wa.me/').replace(
queryParameters: {
'text': locationUrl,
},
).toString();
final url = Uri.parse(whatsappUrl);
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
showSnakbar('Whatsapp not installed');
}
}
Upvotes: 0
Reputation: 61
I solved this issue using the code below
final maps = Uri.https("google.com", "/maps/search/", { "api=1&query": "$lat,$lng" });
Upvotes: 2