Example #1
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            placemark = placemark.Escape();
            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"bingmaps:?where=" +
                      $"{placemark.Thoroughfare}" +
                      $"%20{placemark.Locality}" +
                      $"%20{placemark.AdminArea}" +
                      $"%20{placemark.PostalCode}" +
                      $"%20{placemark.CountryName}";
            }
            else
            {
                uri = $"bingmaps:?rtp=~adr." +
                      $"{placemark.Thoroughfare}" +
                      $"%20{placemark.Locality}" +
                      $"%20{placemark.AdminArea}" +
                      $"%20{placemark.PostalCode}" +
                      $"%20{placemark.CountryName}" +
                      $"{GetMode(options.NavigationMode)}";
            }

            return(LaunchUri(new Uri(uri)));
        }
Example #2
0
        internal static async Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            var address = new MKPlacemarkAddress
            {
                CountryCode = placemark.CountryCode,
                Country     = placemark.CountryName,
                State       = placemark.AdminArea,
                Street      = placemark.Thoroughfare,
                City        = placemark.Locality,
                Zip         = placemark.PostalCode
            };

            var coder = new CLGeocoder();

            CLPlacemark[] placemarks = null;
            try
            {
                placemarks = await coder.GeocodeAddressAsync(address.Dictionary);
            }
            catch
            {
                Debug.WriteLine("Unable to get geocode address from address");
                return;
            }

            if ((placemarks?.Length ?? 0) == 0)
            {
                Debug.WriteLine("No locations exist, please check address.");
            }

            await OpenPlacemark(new MKPlacemark(placemarks[0].Location.Coordinate, address), options);
        }
Example #3
0
        public static Task OpenAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(PlatformOpenMapsAsync(latitude, longitude, options));
        }
        private async void btnPostoProximo_Clicked(object sender, System.EventArgs e)
        {
            var location = new Xamarin.Essentials.Location(PostoProximo.Latitude, PostoProximo.Longitude);
            var options  = new Xamarin.Essentials.MapLaunchOptions {
                NavigationMode = Xamarin.Essentials.NavigationMode.Driving
            };

            await Xamarin.Essentials.Map.OpenAsync(location, options);
        }
Example #5
0
        public static Task OpenAsync(Placemark placemark, MapLaunchOptions options)
        {
            if (placemark == null)
            {
                throw new ArgumentNullException(nameof(placemark));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(PlatformOpenMapsAsync(placemark, options));
        }
Example #6
0
        public static Task OpenAsync(Location location, MapLaunchOptions options)
        {
            if (location == null)
            {
                throw new ArgumentNullException(nameof(location));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(PlatformOpenMapsAsync(location.Latitude, location.Longitude, options));
        }
Example #7
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"bingmaps:?where={placemark.GetEscapedAddress()}";
            }
            else
            {
                uri = $"bingmaps:?rtp=~adr.{placemark.GetEscapedAddress()}{GetMode(options.NavigationMode)}";
            }

            return(LaunchUri(new Uri(uri)));
        }
Example #8
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Pick,
                Uri       = "geo:",
            };

            appControl.Uri += $"0,0?q={placemark.GetEscapedAddress()}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Example #9
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.Pick,
                Uri       = "geo:",
            };

            placemark       = placemark.Escape();
            appControl.Uri += $"0,0?q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Example #10
0
        internal static async Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
#if __IOS__
            var address = new MKPlacemarkAddress
            {
                CountryCode = placemark.CountryCode,
                Country     = placemark.CountryName,
                State       = placemark.AdminArea,
                Street      = placemark.Thoroughfare,
                City        = placemark.Locality,
                Zip         = placemark.PostalCode
            }.Dictionary;
#else
            var address = new NSMutableDictionary
            {
                [CNPostalAddressKey.City]           = new NSString(placemark.Locality ?? string.Empty),
                [CNPostalAddressKey.Country]        = new NSString(placemark.CountryName ?? string.Empty),
                [CNPostalAddressKey.State]          = new NSString(placemark.AdminArea ?? string.Empty),
                [CNPostalAddressKey.Street]         = new NSString(placemark.Thoroughfare ?? string.Empty),
                [CNPostalAddressKey.PostalCode]     = new NSString(placemark.PostalCode ?? string.Empty),
                [CNPostalAddressKey.IsoCountryCode] = new NSString(placemark.CountryCode ?? string.Empty)
            };
#endif

            var           coder = new CLGeocoder();
            CLPlacemark[] placemarks;
            try
            {
                placemarks = await coder.GeocodeAddressAsync(address);
            }
            catch
            {
                Debug.WriteLine("Unable to get geocode address from address");
                return;
            }

            if ((placemarks?.Length ?? 0) == 0)
            {
                Debug.WriteLine("No locations exist, please check address.");
            }

            await OpenPlacemark(new MKPlacemark(placemarks[0].Location.Coordinate, address), options);
        }
Example #11
0
        static Task OpenPlacemark(MKPlacemark placemark, MapLaunchOptions options)
        {
            var mapItem = new MKMapItem(placemark)
            {
                Name = options.Name ?? string.Empty
            };

            MKLaunchOptions launchOptions = null;

            if (options.NavigationMode != NavigationMode.None)
            {
                var mode = MKDirectionsMode.Default;

                switch (options.NavigationMode)
                {
                case NavigationMode.Driving:
                    mode = MKDirectionsMode.Driving;
                    break;

                case NavigationMode.Transit:
                    mode = MKDirectionsMode.Transit;
                    break;

                case NavigationMode.Walking:
                    mode = MKDirectionsMode.Walking;
                    break;

                case NavigationMode.Default:
                    mode = MKDirectionsMode.Default;
                    break;
                }
                launchOptions = new MKLaunchOptions
                {
                    DirectionsMode = mode
                };
            }

            var mapItems = new[] { mapItem };

            MKMapItem.OpenMaps(mapItems, launchOptions);
            return(Task.CompletedTask);
        }
Example #12
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:0,0?q={placemark.GetEscapedAddress()}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.GetEscapedAddress()}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
Example #13
0
        internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
            placemark = placemark.Escape();
            var uri = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:0,0?q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}";
                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={placemark.Thoroughfare} {placemark.Locality} {placemark.AdminArea} {placemark.PostalCode} {placemark.CountryName}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }
        internal static async Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
        {
#if __IOS__
            var address = new MKPlacemarkAddress
            {
                CountryCode = placemark.CountryCode,
                Country     = placemark.CountryName,
                State       = placemark.AdminArea,
                Street      = placemark.Thoroughfare,
                City        = placemark.Locality,
                Zip         = placemark.PostalCode
            }.Dictionary;
#else
            var address = new NSMutableDictionary
            {
                [CNPostalAddressKey.City]           = new NSString(placemark.Locality ?? string.Empty),
                [CNPostalAddressKey.Country]        = new NSString(placemark.CountryName ?? string.Empty),
                [CNPostalAddressKey.State]          = new NSString(placemark.AdminArea ?? string.Empty),
                [CNPostalAddressKey.Street]         = new NSString(placemark.Thoroughfare ?? string.Empty),
                [CNPostalAddressKey.PostalCode]     = new NSString(placemark.PostalCode ?? string.Empty),
                [CNPostalAddressKey.IsoCountryCode] = new NSString(placemark.CountryCode ?? string.Empty)
            };
#endif

            var resolvedPlacemarks = await GetPlacemarksAsync(address);

            if (resolvedPlacemarks?.Length > 0)
            {
                await OpenPlacemark(new MKPlacemark(resolvedPlacemarks[0].Location.Coordinate, address), options);
            }
            else
            {
#if __IOS__ || __MACOS__
                // https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
                var uri   = $"http://maps.apple.com/?q={placemark.GetEscapedAddress()}";
                var nsurl = NSUrl.FromString(uri);

                await Launcher.PlatformOpenAsync(nsurl);
#else
                await OpenPlacemark(new MKPlacemark(default, address), options);
Example #15
0
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            var lat  = latitude.ToString(CultureInfo.InvariantCulture);
            var lng  = longitude.ToString(CultureInfo.InvariantCulture);
            var name = options.Name ?? string.Empty;
            var uri  = string.Empty;

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"bingmaps:?collection=point.{lat}_{lng}_{name}";
            }
            else
            {
                uri = $"bingmaps:?rtp=~pos.{lat}_{lng}_{name}{GetMode(options.NavigationMode)}";
            }

            return(LaunchUri(new Uri(uri)));
        }
Example #16
0
 internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
 => throw new NotImplementedInReferenceAssemblyException();
Example #17
0
 internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
 => throw new NotImplementedInReferenceAssemblyException();
Example #18
0
 public static Task OpenMapsAsync(this Placemark placemark, MapLaunchOptions options) =>
 Map.OpenAsync(placemark, options);
Example #19
0
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            Permissions.EnsureDeclared <Permissions.LaunchApp>();

            var appControl = new AppControl
            {
                Operation = AppControlOperations.View,
                Uri       = "geo:",
            };

            appControl.Uri += $"{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}";

            AppControl.SendLaunchRequest(appControl);

            return(Task.CompletedTask);
        }
Example #20
0
 internal static Task PlatformOpenMapsAsync(Placemark placemark, MapLaunchOptions options)
 => throw ExceptionUtils.NotSupportedOrImplementedException;
Example #21
0
 internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
 => throw ExceptionUtils.NotSupportedOrImplementedException;
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            if (string.IsNullOrWhiteSpace(options.Name))
            {
                options.Name = string.Empty;
            }

            NSDictionary dictionary = null;
            var          placemark  = new MKPlacemark(new CLLocationCoordinate2D(latitude, longitude), dictionary);

            return(OpenPlacemark(placemark, options));
        }
Example #23
0
 public static Task OpenMapsAsync(this Location location, MapLaunchOptions options) =>
 Map.OpenAsync(location, options);
Example #24
0
        internal static Task PlatformOpenMapsAsync(double latitude, double longitude, MapLaunchOptions options)
        {
            var uri = string.Empty;
            var lat = latitude.ToString(CultureInfo.InvariantCulture);
            var lng = longitude.ToString(CultureInfo.InvariantCulture);

            if (options.NavigationMode == NavigationMode.None)
            {
                uri = $"geo:{lat},{lng}?q={lat},{lng}";

                if (!string.IsNullOrWhiteSpace(options.Name))
                {
                    uri += $"({AndroidUri.Encode(options.Name)})";
                }
            }
            else
            {
                uri = $"google.navigation:q={lat},{lng}{GetMode(options.NavigationMode)}";
            }

            StartIntent(uri);
            return(Task.CompletedTask);
        }