Issue
I am running into a little issue in which Safari is opening before directly launching into the native Apple Maps app in Xamarin. I followed this tutorial somewhat: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/map/native-map-app
var locationUrl = Device.RuntimePlatform == Device.iOS ?
$"http://maps.apple.com/?q={address}" :
$"http://maps.google.com/?q={address}";
var uri = new Uri( locationUrl ).AbsoluteUri;
try
{
await Launcher.OpenAsync( uri );
}
catch
{
await AppState.Current.NavigateToExternalBrowserAsync( uri );
}
This works perfectly in Android and launches directly into the native application. I followed this apple maps scheme: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html. Any help would be much appreciated!
Solution
Contrary to what the documentation says in the archives and prior answers, the maps:// scheme seems to create the behavior I anticipated.,
So, updating the Apple URI to:
$"maps://http://maps.apple.com/?q={address}"
Works beautifully.
The entire snippet:
var locationUrl = Device.RuntimePlatform == Device.iOS ?
$"maps://http://maps.apple.com/?q={address}" :
$"http://maps.google.com/?q={address}";
var uri = new Uri( locationUrl );
try
{
await Launcher.OpenAsync( locationUrl );
}
catch
{
await AppState.Current.NavigateToExternalBrowserAsync( uri.AbsoluteUri );
}
creates the anticipated behavior of opening natively in the maps application without safari as an intermediary. The only downside is that if a user is on an Apple device and has uninstalled the maps app (which is speculatively rare), it will prompt them to restore the maps application.
Answered By - Bart
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.