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.
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 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"
I'm following this guide, I'm having this code:
var acs = ActionCodeSettings(
url: 'https://example.com/auth/widget',
androidPackageName: 'com.example',
iOSBundleId: 'com.example',
handleCodeInApp: true,
androidInstallApp: true,
androidMinimumVersion: '12',
);
var emailAuth = 'john.doe#pm.me';
FirebaseAuth.instance
.sendSignInLinkToEmail(
email: emailAuth, actionCodeSettings: acs)
.catchError((onError, stackTrace) {})
.then((value) =>
print('Successfully sent email verification'));
Sending the email works, but when I click on the email, then…
in iOS it opens https://example.com/auth/widget - which is the fallback
in Android it shows a circular loader for about 1s and then it "falls down" and nothing happens
The incoming link handler
FirebaseDynamicLinks.instance.onLink.listen((dynamicLinkData) {
print('got dynamic link! $dynamicLinkData');
}).onError((error) {
print('error error!');
});
I configured dynamic links in Firebase to point to to.example.com. I also added a manual dynamic link to.example.com/test which opens my app (the got dynamic link! message shows up) - so all seems fine, the problem seems to lie in the link generation.
The link structure I get by email is:
https://to.example.com/?link=https://example-abcd.firebaseapp.com/__/auth/action?apiKey…%26continueUrl%3Dhttps://example.com/auth/widget%26lang%3Den&apn=com.example&amv=12&ibi=com.example&ifl=https://example-abcd.firebaseapp.com/__/auth/action?apiKey%3D…%26continueUrl%3Dhttps://example.com/auth/widget%26lang%3Den
After some more painful hours of debugging and reading documentation I finally found it out. Most of this is in the flutter documentation, but since the documentation has broken links and is a bit all over the place it was hard for me to catch it all!
Android
I needed to decrease the androidMinimumVersion from 12 to 1. Then my app opens and I can receive the dynamic link. No idea why. My android simulator is android version 13 but the app never opened.
Before decreasing the android version I also set the sha256 setting in firebase, using gradlew signingReport documented in this answer. Not sure though this was required.
iOS
I forgot to do all the steps documented in receiving links on iOS section, namely:
add the dynamic links domain into associated domains
add FirebaseDynamicLinksCustomDomains into Info.plist
Overall, I found that to get this feature working was really really hard for me as a Flutter beginner. But I guess a lot of the setup I can re-use as the dynamic links capability seems to be something which comes in handy in the future.
I am using flutter_webview_plugin: ^0.3.11
This is my code
Widget build(BuildContext context){
return WebviewScaffold(
url: glbPhotoURL,
withJavascript: true,
scrollBar : true,
withZoom: true
)
url: glbPhotoURL => here glbPhotoURL is a URL that I am passing
When I am using any normal URL it is running fine (like http://www.google.com, http://youtube.com"
Even url like - https://youtu.be/o5UPfG1eIw4 is running fine
But when I am using any google photo url (short url) it is throwing an error net::ERR_UNKNOWN_URL_SCHEME for eg - https://photos.app.goo.gl/FkQenAD8kQQc4TSr6
If I am using the expanded URL it shows the pictures -https://photos.google.com/share/AF1QipNItZG3Cg_hn9__2QnuVh3nNMbRuGxQaQSWZ76qni7L7h0ORbauolcH3AKe0MOnEA?
key=emc1Mk1CenRJRjloMjV5V1AzcmczNUprcGFsbmR3
Please help me resolve the issue
As of now I am running it on Android physical device.
Google Photos uses Firebase Dynamic Links. I suggest launching the link externally. I encountered a similar error on Android before, when Firebase Dynamic Links are being forced to be loaded in a WebView. FDLs are expected to be handled by Google Play Services in Android. But since the WebView doesn't know what to do with the link it's forced to display, the WebView returns "net::ERR_UNKNOWN_URL_SCHEME" error.
Open the link externally by using url_launcher. Use RegEx to filter intent URLs and check if the URL can be launched and be handled externally (outside the app).
var yourURL = "URL goes here";
// Check if URL contains Google Photos URL
yourURL.contains(RegExp('^https://photos\.app\.goo\.gl/.*$')){
// Check if the URL can be launched
if (await canLaunch(yourURL)) {
await launch(yourURL);
} else {
print('Could not launch $yourURL');
}
}