/// <summary>
        /// Navigate to specific latitude and longitude.
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="latitude">Lat</param>
        /// <param name="longitude">Long</param>
        /// <param name="navigationType">Type of navigation</param>
        public Task <bool> NavigateTo(string name, double latitude, double longitude, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = string.Empty;
            }

            try
            {
                NSDictionary dictionary = null;
                var          mapItem    = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(latitude, longitude), dictionary));
                mapItem.Name = name;

                MKLaunchOptions launchOptions = null;
                if (navigationType != NavigationType.Default)
                {
                    launchOptions = new MKLaunchOptions
                    {
                        DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                    };
                }

                var mapItems = new[] { mapItem };
                MKMapItem.OpenMaps(mapItems, launchOptions);
                return(Task.FromResult(true));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to launch maps: " + ex);
                return(Task.FromResult(false));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Navigate to specific latitude and longitude.
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="latitude">Lat</param>
        /// <param name="longitude">Long</param>
        /// <param name="navigationType">Type of navigation</param>
        public void NavigateTo(string name, double latitude, double longitude, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = string.Empty;
            }

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

            mapItem.Name = name;

            MKLaunchOptions launchOptions = null;

            if (navigationType != NavigationType.Default)
            {
                launchOptions = new MKLaunchOptions
                {
                    DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                };
            }

            var mapItems = new[] { mapItem };

            MKMapItem.OpenMaps(mapItems, launchOptions);
        }
        /// <summary>
        /// Navigate to specific latitude and longitude.
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="latitude">Lat</param>
        /// <param name="longitude">Long</param>
        /// <param name="navigationType">Type of navigation</param>
        public Task<bool> NavigateTo(string name, double latitude, double longitude, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
                name = string.Empty;

            try
            {

                NSDictionary dictionary = null;
                var mapItem = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(latitude, longitude), dictionary));
                mapItem.Name = name;

                MKLaunchOptions launchOptions = null;
                if (navigationType != NavigationType.Default)
                {
                    launchOptions = new MKLaunchOptions
                    {
                        DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                    };
                }

                var mapItems = new[] { mapItem };
                MKMapItem.OpenMaps(mapItems, launchOptions);
                return Task.FromResult(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to launch maps: " + ex);
                return Task.FromResult(false);
            }
        }
Ejemplo n.º 4
0
        static Task OpenPlacemark(MKPlacemark placemark, MapsLaunchOptions options)
        {
            var mapItem = new MKMapItem(placemark)
            {
                Name = options.Name ?? string.Empty
            };

            var mode = MKDirectionsMode.Default;

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

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

            case MapDirectionsMode.Walking:
                mode = MKDirectionsMode.Walking;
                break;
            }

            var launchOptions = new MKLaunchOptions
            {
                DirectionsMode = mode
            };

            var mapItems = new[] { mapItem };

            MKMapItem.OpenMaps(mapItems, launchOptions);
            return(Task.CompletedTask);
        }
        static void OpenIOSMap(Place place)
        {
            double latitude = place.Latitude;
            double longitude = place.Longitude;
            CLLocationCoordinate2D center = new CLLocationCoordinate2D (latitude, longitude);

            MKPlacemark placemark = new MKPlacemark (center, null);
            MKMapItem mapItem = new MKMapItem (placemark);
            mapItem.Name = place.Name;
            MKLaunchOptions options = new MKLaunchOptions ();
            options.MapSpan = MKCoordinateRegion.FromDistance (center, 200, 200).Span;
            mapItem.OpenInMaps (options);
        }
Ejemplo n.º 6
0
        public void ShowGmaps(double lat, double lon)
        {
            CLLocationCoordinate2D coordinate_end = new CLLocationCoordinate2D(lat, lon);
            MKPlacemark            placeMark_end  = new MKPlacemark(coordinate_end, new MKPlacemarkAddress());
            MKMapItem mapItem_end = new MKMapItem(placeMark_end);

            MKMapItem mapItem_start = MKMapItem.MapItemForCurrentLocation();

            MKLaunchOptions options = new MKLaunchOptions();

            options.DirectionsMode = MKDirectionsMode.Driving;

            MKMapItem.OpenMaps(new MKMapItem[] { mapItem_start, mapItem_end }, options);
        }
        private void OpenMapButton_TouchUpInside(object sender, EventArgs e)
        {
            CLLocationCoordinate2D coord = new CLLocationCoordinate2D(target.Lat, target.Long);

            MKMapItem mapItem = new MKMapItem(new MKPlacemark(coord))
            {
                Name = "Target Location"
            };

            MKLaunchOptions launchOptions = new MKLaunchOptions
            {
                DirectionsMode = MKDirectionsMode.Walking
            };

            mapItem.OpenInMaps(launchOptions);
        }
Ejemplo n.º 8
0
    /// <summary>
    /// Starts the Native Map Navigation
    /// Implementation from https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/ExternalMaps
    /// </summary>
    /// <param name="navigationModel"></param>
    public void LaunchNavigationAsync(NavigationModel navigationModel)
    {
      var mapItem =
        new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(navigationModel.Latitude, navigationModel.Longitude),
          new MKPlacemarkAddress{Street = navigationModel.DestinationAddress})) {Name = navigationModel.DestinationName};

      var launchOptions =
         new MKLaunchOptions
        {
          DirectionsMode =  MKDirectionsMode.Driving
        };

      var mapItems = new[] { mapItem };

      MKMapItem.OpenMaps(mapItems, launchOptions);
    }
        void Directions_TouchUpInside(object sender, EventArgs e)
        {
            var location = new CLLocationCoordinate2D(this.Cinema.Latitude, this.Cinema.Longitute);
            MKPlacemarkAddress address = null;
            var placemark = new MKPlacemark(location, address);

            var mapItem = new MKMapItem(placemark);

            mapItem.Name = String.Format("Cineworld {0}", this.Cinema.Name);

            var launchOptions = new MKLaunchOptions();

            launchOptions.DirectionsMode = (sender == this.btnWalkingDirections) ? MKDirectionsMode.Walking : MKDirectionsMode.Driving;
            launchOptions.ShowTraffic    = (sender == this.btnDrivingDirections);
            launchOptions.MapType        = MKMapType.Standard;

            mapItem.OpenInMaps(launchOptions);
        }
    /// <summary>
    /// Navigate to specific latitude and longitude.
    /// </summary>
    /// <param name="name">Label to display</param>
    /// <param name="latitude">Lat</param>
    /// <param name="longitude">Long</param>
    /// <param name="navigationType">Type of navigation</param>
    public void NavigateTo(string name, double latitude, double longitude, NavigationType navigationType = NavigationType.Default)
    {
      if (string.IsNullOrWhiteSpace(name))
        name = string.Empty;

      NSDictionary dictionary = null;
      var mapItem = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(latitude, longitude), dictionary));
      mapItem.Name = name;

      MKLaunchOptions launchOptions = null;
      if(navigationType != NavigationType.Default)
      {
        launchOptions = new MKLaunchOptions
        {
          DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
        };
      }

      var mapItems = new[] { mapItem };
      MKMapItem.OpenMaps(mapItems, launchOptions);
    }
Ejemplo n.º 11
0
        /// <summary>
        /// Starts the Native Map Navigation
        /// Implementation from https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/ExternalMaps
        /// </summary>
        /// <param name="navigationModel"></param>
        public void LaunchNavigationAsync(NavigationModel navigationModel)
        {
            var mapItem =
                new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(navigationModel.Latitude, navigationModel.Longitude),
                                              new MKPlacemarkAddress {
                Street = navigationModel.DestinationAddress
            }))
            {
                Name = navigationModel.DestinationName
            };

            var launchOptions =
                new MKLaunchOptions
            {
                DirectionsMode = MKDirectionsMode.Driving
            };

            var mapItems = new[] { mapItem };

            MKMapItem.OpenMaps(mapItems, launchOptions);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Navigate to an address
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="street">Street</param>
        /// <param name="city">City</param>
        /// <param name="state">Sate</param>
        /// <param name="zip">Zip</param>
        /// <param name="country">Country</param>
        /// <param name="countryCode">Country Code if applicable</param>
        /// <param name="navigationType">Navigation type</param>
        public async void NavigateTo(string name, string street, string city, string state, string zip, string country, string countryCode, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(street))
            {
                street = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(city))
            {
                city = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(state))
            {
                state = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(zip))
            {
                zip = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(country))
            {
                country = string.Empty;
            }

            var placemarkAddress = new MKPlacemarkAddress
            {
                City        = city,
                Country     = country,
                State       = state,
                Street      = street,
                Zip         = zip,
                CountryCode = countryCode
            };

            var coder      = new CLGeocoder();
            var placemarks = await coder.GeocodeAddressAsync(placemarkAddress.Dictionary);

            if (placemarks.Length == 0)
            {
                Debug.WriteLine("Unable to get geocode address from address");
                return;
            }

            CLPlacemark placemark = placemarks[0];

            var mapItem = new MKMapItem(new MKPlacemark(placemark.Location.Coordinate, placemarkAddress));

            mapItem.Name = name;

            MKLaunchOptions launchOptions = null;

            if (navigationType != NavigationType.Default)
            {
                launchOptions = new MKLaunchOptions
                {
                    DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                };
            }

            var mapItems = new[] { mapItem };

            MKMapItem.OpenMaps(mapItems, launchOptions);
        }
        /// <summary>
        /// Navigate to an address
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="street">Street</param>
        /// <param name="city">City</param>
        /// <param name="state">Sate</param>
        /// <param name="zip">Zip</param>
        /// <param name="country">Country</param>
        /// <param name="countryCode">Country Code if applicable</param>
        /// <param name="navigationType">Navigation type</param>
        public async Task <bool> NavigateTo(string name, string street, string city, string state, string zip, string country, string countryCode, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(street))
            {
                street = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(city))
            {
                city = string.Empty;
            }

            if (string.IsNullOrWhiteSpace(state))
            {
                state = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(zip))
            {
                zip = string.Empty;
            }


            if (string.IsNullOrWhiteSpace(country))
            {
                country = string.Empty;
            }


            CLPlacemark[]      placemarks       = null;
            MKPlacemarkAddress placemarkAddress = null;

            try
            {
                placemarkAddress = new MKPlacemarkAddress
                {
                    City        = city,
                    Country     = country,
                    State       = state,
                    Street      = street,
                    Zip         = zip,
                    CountryCode = countryCode
                };

                var coder = new CLGeocoder();

                placemarks = await coder.GeocodeAddressAsync(placemarkAddress.Dictionary);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to get geocode address from address: " + ex);
                return(false);
            }

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

            try
            {
                var placemark = placemarks[0];

                var mapItem = new MKMapItem(new MKPlacemark(placemark.Location.Coordinate, placemarkAddress));
                mapItem.Name = name;

                MKLaunchOptions launchOptions = null;
                if (navigationType != NavigationType.Default)
                {
                    launchOptions = new MKLaunchOptions
                    {
                        DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                    };
                }

                var mapItems = new[] { mapItem };
                MKMapItem.OpenMaps(mapItems, launchOptions);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to launch maps: " + ex);
            }

            return(true);
        }
        /// <summary>
        /// Navigate to an address
        /// </summary>
        /// <param name="name">Label to display</param>
        /// <param name="street">Street</param>
        /// <param name="city">City</param>
        /// <param name="state">Sate</param>
        /// <param name="zip">Zip</param>
        /// <param name="country">Country</param>
        /// <param name="countryCode">Country Code if applicable</param>
        /// <param name="navigationType">Navigation type</param>
        public async Task<bool> NavigateTo(string name, string street, string city, string state, string zip, string country, string countryCode, NavigationType navigationType = NavigationType.Default)
        {
            if (string.IsNullOrWhiteSpace(name))
                name = string.Empty;


            if (string.IsNullOrWhiteSpace(street))
                street = string.Empty;


            if (string.IsNullOrWhiteSpace(city))
                city = string.Empty;

            if (string.IsNullOrWhiteSpace(state))
                state = string.Empty;


            if (string.IsNullOrWhiteSpace(zip))
                zip = string.Empty;


            if (string.IsNullOrWhiteSpace(country))
                country = string.Empty;


            CLPlacemark[] placemarks = null;
            MKPlacemarkAddress placemarkAddress = null;
            try
            {
                placemarkAddress = new MKPlacemarkAddress
                {
                    City = city,
                    Country = country,
                    State = state,
                    Street = street,
                    Zip = zip,
                    CountryCode = countryCode
                };

                var coder = new CLGeocoder();
                
                placemarks = await coder.GeocodeAddressAsync(placemarkAddress.Dictionary);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to get geocode address from address: " + ex);
                return false;
            }

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

            try
            {
                var placemark = placemarks[0];

                var mapItem = new MKMapItem(new MKPlacemark(placemark.Location.Coordinate, placemarkAddress));
                mapItem.Name = name;

                MKLaunchOptions launchOptions = null;
                if (navigationType != NavigationType.Default)
                {
                    launchOptions = new MKLaunchOptions
                    {
                        DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
                    };
                }

                var mapItems = new[] { mapItem };
                MKMapItem.OpenMaps(mapItems, launchOptions);
            }
            catch(Exception ex)
            {
                Debug.WriteLine("Unable to launch maps: " + ex);
            }

            return true;
        }
    /// <summary>
    /// Navigate to an address
    /// </summary>
    /// <param name="name">Label to display</param>
    /// <param name="street">Street</param>
    /// <param name="city">City</param>
    /// <param name="state">Sate</param>
    /// <param name="zip">Zip</param>
    /// <param name="country">Country</param>
    /// <param name="countryCode">Country Code if applicable</param>
    /// <param name="navigationType">Navigation type</param>
    public async void NavigateTo(string name, string street, string city, string state, string zip, string country, string countryCode, NavigationType navigationType = NavigationType.Default)
    {
      if (string.IsNullOrWhiteSpace(name))
        name = string.Empty;


      if (string.IsNullOrWhiteSpace(street))
        street = string.Empty;


      if (string.IsNullOrWhiteSpace(city))
        city = string.Empty;

      if (string.IsNullOrWhiteSpace(state))
        state = string.Empty;


      if (string.IsNullOrWhiteSpace(zip))
        zip = string.Empty;


      if (string.IsNullOrWhiteSpace(country))
        country = string.Empty;

      var placemarkAddress = new MKPlacemarkAddress
      {
        City = city,
        Country = country,
        State = state,
        Street = street,
        Zip = zip,
        CountryCode = countryCode
      };

      var coder = new CLGeocoder();
      var placemarks = await coder.GeocodeAddressAsync(placemarkAddress.Dictionary);

      if(placemarks.Length == 0)
      {
        Debug.WriteLine("Unable to get geocode address from address");
        return;
      }

      CLPlacemark placemark = placemarks[0];

      var mapItem = new MKMapItem(new MKPlacemark(placemark.Location.Coordinate, placemarkAddress));
      mapItem.Name = name;

      MKLaunchOptions launchOptions = null;
      if (navigationType != NavigationType.Default)
      {
        launchOptions = new MKLaunchOptions
        {
          DirectionsMode = navigationType == NavigationType.Driving ? MKDirectionsMode.Driving : MKDirectionsMode.Walking
        };
      }

      var mapItems = new[] { mapItem };
      MKMapItem.OpenMaps(mapItems, launchOptions);
    }
Ejemplo n.º 16
0
		/// <summary>
		/// Открытие станции в приложении "Карты" от iOS
		/// </summary>
		public void OpenMapForPlace ()
		{
			const int regionDistance = 10000;
			var point = station.Point;
			var coord = new CLLocationCoordinate2D (point.Latitude, point.Longitude);
			var region = MKCoordinateRegion.FromDistance (coord, regionDistance, regionDistance);
			MKPlacemarkAddress address = null;
			var placemark = new MKPlacemark(coord,address);
			var mapItem = new MKMapItem (placemark);
			var option = new MKLaunchOptions ();
			option.MapCenter = region.Center;
			option.MapSpan = region.Span;
			mapItem.Name =station.StationTitle;
			mapItem.OpenInMaps (option);
		}