I am trying to find what link I can place in my code that will allow me to automatically open google maps and starts a path to my adress, right now I have this:
Future<void> _openMapsWithDirection(String adress) async {
final uri =
Uri.parse("https://www.google.com/maps/search/?api=1&query=$adress");
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $uri';
}
}
this code allows me to open google maps with my desire adress, but I need to press "start" in order to app start to work, I know that there must be a link that will tell google maps to start this path from my current location to desire adress, but I do not know where to even search it.
I am using url_launcher package, there is a option to use maps_launcher, but I did everythink on url_launcher, and I want at least try this way.
I found this page: https://developers.google.com/maps/documentation/urls/get-started.
Where is for example "https://www.google.com/maps/dir/?api=1&origin=Google+Pyrmont+NSW&destination=QVB&destination_place_id=ChIJISz8NjyuEmsRFTQ9Iw7Ear8&travelmode=walking", and this allows me to go from a place to my adress, but how I can get my CURRENT location?
I found solution in here:
Current Location - Google Maps - Link to Directions
the solution link is "https://www.google.com/maps/dir/Current+Location/$adress"
Related
I just released my first app and It has a button in it that takes you to a website.
A user just sent me this:.
I tried googling Google's secure browsers policy but not much info is coming up.
how can I make my app comply with this policy? I think the button opens a browser in app (I use duckduckgo as my default browser and haven't had an issue)
is it just a case of opening a browser and then heading to the website when the button is pressed?
my code to open the website is:
_launchURL() async {
const url = 'https://www.thiswebsite.com';
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
}
thanks so much and any help would be greatly appreciated
Google is trying to make sure, you open this window in an actual new browser window, not in a webview still under the control of your application.
Your code should open an external browser.
Maybe the user has no browser installed on their device? Maybe their default browser is some exotic thing not recognized by Google?
If you are using the latest version of url_launcher (currently 6.1.8) there is not a lot more you can do.
You could force the app to take the external browser, not the in-app webview:
await launchUrl(_url,mode: LaunchMode.externalApplication);
But that should be what happens anyway. If your version is up to date, ask your user, what browser they use. Be prepared to tell them that they need to use another one.
I want to open Google calendar app more specifically the create event page in the app from my another flutter app.
I am using the URL launcher package but it opens the app in chrome
What change should I make in the URL so that the add event page opens directly in the google calendar app.
Currently my URL looks like below
https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda
My code for that part is as below
if (await canLaunchUrl(Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'))) {
await launchUrl(
Uri.parse('https://calendar.google.com/calendar/u/0/r/eventedit?dates=20210226T033000/20210226T040000&ctz=Asia/Calcutta&location&text=Blawsome:+A+Crystal+Alchemy+Healing+Meditation&details=Parth+Pitroda'),
mode: LaunchMode.externalApplication);
} else {
throw 'Could not launch URL';
}
rathe than using a HTTP request, you could use googleapis package from https://pub.dev which has inbuilt methods to create Google Calender events directly within the Calender app.
Check package and documentation here.
Happy coding!
I have a navigation button which when clicked on should be opening either the Google maps or the Apple maps app, whichever is installed, and show navigation directions from current location to destination location
I have tried the following approaches using the url_launcher package
await launchUrlString("https://www.google.com/maps/dir/?api=1&origin=${position.latitude},${position.longitude}&destination=${vendorPosition.latitude},${vendorPosition.longitude}");
await launchUrl(Uri.parse("google.navigation:q=${position.latitude},${position.longitude}&mode=d"));
Neither of the approaches are working as expected, especially since this is only using google maps URI
There is another package just to launch maps
https://pub.dev/packages/map_launcher
final availableMaps = await MapLauncher.installedMaps;
print(availableMaps); // [AvailableMap { mapName: Google Maps, mapType: google }, ...]
await availableMaps.first.showMarker(
coords: Coords(37.759392, -122.5107336),
title: "Ocean Beach",
);
It supports google maps and apple map too.. Url Launcher's default behaviour is to open default browser.
Sorry to ask this here but couldnt find any information related to this online. In native java I have used intent to select com.whatsapp.w4b and com.whatsapp.
I cant figure out how to do it with dart. So far I know:
String androidUrl = 'https://wa.me/$recipientMobile/?text=${Uri.parse(message)}';
String iosUrl = 'https://api.whatsapp.com/send?phone=$recipientMobile=${Uri.parse(message)}';
if (Platform.isAndroid) {
await launch(androidUrl);
} else if (Platform.isIOS) {
if(await canLaunch(iosUrl)){
await launch(iosUrl);
} else {
showToast('Error! Try again.', 'Short');
}
}
This code works but only launches default WhatsApp. How to launch bussiness / personal whatsapp?
Thanks in advance.
EITHER you'll have to ask the users to change the defaults in the link settings of the phone as suggested here.
OR you'll have to share a link that they paste in the browser which will open the app selection section of the phone with both the options, as shown here.
The function getExternalStorageDirectory() and ApplicationDocumentDirectory() gives the same directory to me that is inside the android folder. I like to create a folder in storage/emulated/0 , i tried explicitly creating it with
Directory('storage/emulated/0').create(); then it says you have no permission. And i gave all the possible permissions and still gets the same result. Is there any way to create a folder in storage/emulated/0 ?
NB: _getPermission returns a bool according to the permission status. This code works well in an emulator but it is not working in an actual device.
takePhoto(BuildContext context) async {
if ( await _getPermission(Permission.manageExternalStorage)){
final image =await picker.pickImage(source: ImageSource.camera);
var newPath = "storage/emulated/0/takephotosaver";
var directory = Directory(newPath).create();
File fileIMage = File(image!.path);
var imageName = DateTime.now().toString();
fileIMage.copy("$newPath/$imageName.jpg");
Navigator.push(context, MaterialPageRoute(builder: (context)=>MyPreview(fileIMage)));
}
}
}
Edit :-
This code is working in android version 9 and below but not working in android 10 and 11. Is there a way to display the image taken by my camera in a separate folder?
Things have changed after android 10. You shouldn't create folders in storage/emulated/0 now. Google is strict about that, and your app may get rejected if you publish your app in Google PlayStore. If you still want to do that then add this permission in your AndroidManifest.xml.
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
And to get the permission from the user do this,
if (await Permission.manageExternalStorage.request().isGranted) {...}
Edit:
Whenever you create a new file the device can't automatically find it. You'd have to manually tell the device to refresh for the files. Before you'd have to refresh all the files in the device for it to get updated which was very inefficient, but now you could just send the path of the file that you want to get updated. You can use the media_scanner plugin to do so.
Or If you wanna do it yourself with kotlin then here's the code,
private fun broadcastFileUpdate(path: String){
context.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(File(path))))
}