async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var uberRow = e.Item as UberRow;

            if (uberRow == null)
            {
                return;
            }

            var geocoder           = new Geocoder();
            var pickupAddressTask  = geocoder.GetAddressesForPositionAsync(new Position(uberRow.Pickup.Latitude, uberRow.Pickup.Longitude));
            var dropoffAddressTask = geocoder.GetAddressesForPositionAsync(new Position(uberRow.Dropoff.Latitude, uberRow.Dropoff.Longitude));

            await Task.WhenAll(pickupAddressTask, dropoffAddressTask);

            var pickupAddress  = pickupAddressTask.Result.FirstOrDefault();
            var dropoffAddress = dropoffAddressTask.Result.FirstOrDefault();

            string alertMessage = $"Pickup from {pickupAddress} and dropoff at {dropoffAddress}";
            var    openMaps     = await DisplayAlert("Ride Selected", alertMessage, "Open in Maps", "Back");

            if (openMaps)
            {
                var origin      = HttpUtility.UrlPathEncode(pickupAddress);
                var destination = HttpUtility.UrlPathEncode(dropoffAddress);

                var mapsUri = new Uri($"https://www.google.com/maps/dir/?api=1&origin={origin}&destination={destination}");
                Device.OpenUri(mapsUri);
            }

            //Deselect Item
            ((ListView)sender).SelectedItem = null;
        }
Esempio n. 2
0
        public SMapPage(/*Pin pin*/)
        {
            InitializeComponent();
            map.MoveToRegion(
                MapSpan.FromCenterAndRadius(
                    new Position(16.7514123, -93.1393565), Distance.FromMiles(3)));


            map.PinDragEnd += async(sender, e) => {
                var lat = _pin.Position.Latitude;
                var lon = _pin.Position.Longitude;
                IEnumerable <string> Adresses = await geo.GetAddressesForPositionAsync(_pin.Position);

                direcc = Adresses.ElementAt(0);

                // await DisplayAlert("Exito", "Latitud: "+lat+" Longitud: "+lon+Environment.NewLine+"Direccion: "+direcc, "Aceptar");
            };


            map.MapClicked += async(sender, e) => {
                var lat = e.Point.Latitude;
                var lon = e.Point.Longitude;
                /*Modal que bloquee la pantalla*/
                ModalMapPage modalPage = new ModalMapPage();
                await Navigation.PushModalAsync(modalPage);

                IEnumerable <string> Adresses = await geo.GetAddressesForPositionAsync(new Position(lat, lon));

                await Navigation.PopModalAsync();

                direcc = Adresses.ElementAt(0);
                _pin   = new Pin()
                {
                    Type     = PinType.Place,
                    Label    = "Lugar",
                    Address  = direcc,
                    Position = new Position(e.Point.Latitude, e.Point.Longitude)
                };
                map.Pins.Clear();
                _pin.IsDraggable = true;
                map.Pins.Add(_pin);
                var res = await DisplayAlert("Ubicación Establecida", "¿Desea establecer la siguiente dirección: " + direcc + "?", "Sí", "NO");

                if (res == true)
                {
                    //NewOrderViewModel.flagSwitchEnabled = true;
                    NewOrderViewModel.pin = _pin;
                }
                else
                {
                    map.Pins.Remove(_pin);
                    _pin = null;
                }
            };
        }
Esempio n. 3
0
        /// <summary>
        /// requests current location and returns a task of string with the best known address
        /// </summary>
        /// <returns></returns>
        public async Task <string> GetAddress()
        {
            try
            {
                possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Position(this.Position.Latitude, this.Position.Longitude));

                return(possibleAddresses.First().ToString());
            }
            catch {
                return($"{this.Position.Latitude},{this.Position.Longitude}");
            }
        }
Esempio n. 4
0
        private async void OnBtnPesquisarClicked(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(EntryCep.Text))
            {
                await DisplayAlert("Erro", "O campo do cep deve ser preenchido", "Ok");

                return;
            }
            Geocoder geocoder     = new Geocoder();
            var      localizacoes = await geocoder.GetPositionsForAddressAsync(EntryCep.Text);

            if (localizacoes.Any())
            {
                var enderecos = await geocoder.GetAddressesForPositionAsync(new Position(localizacoes.FirstOrDefault().Latitude, localizacoes.FirstOrDefault().Longitude));

                var endereco = enderecos.FirstOrDefault();
                EnderecoCompleto   = endereco;
                LabelEndereco.Text = endereco.Substring(0, endereco.IndexOf('-'));
                MapLocalizacao.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(localizacoes.FirstOrDefault().Latitude, localizacoes.FirstOrDefault().Longitude), Distance.FromKilometers(1)));
                MapLocalizacao.Pins.RemoveAt(0);

                var pinCarro = new Pin()
                {
                    Position = new Position(localizacoes.FirstOrDefault().Latitude,
                                            localizacoes.FirstOrDefault().Longitude),
                    Label = "Seu carro"
                };

                MapLocalizacao.Pins.Add(pinCarro);
            }
        }
Esempio n. 5
0
        protected override void OnAppearing()
        {
            ChambersListView.SelectedItem = null;
            var req = WebRequest.CreateHttp(Constants.GetChambersURL);

            req.Method = "GET";
            var resp = new StreamReader(req.GetResponse().GetResponseStream()).ReadToEnd();

            Chambers = JsonConvert.DeserializeObject <List <Chambre> >(resp);
            Device.BeginInvokeOnMainThread(() =>
            {
                ChambersListView.ItemsSource = new ObservableCollection <String>(Chambers.Select(x => x.Nom));
                Chambers.ForEach(async x =>
                {
                    Position position = new Position(x.Latitude, x.Longitude);
                    IEnumerable <string> possibleAddresses = await Geocoder.GetAddressesForPositionAsync(position);
                    string address = possibleAddresses.FirstOrDefault();
                    ChambersMap.Pins.Add(new Pin
                    {
                        Label    = x.Nom,
                        Address  = possibleAddresses.FirstOrDefault(),
                        Position = position
                    });
                });
            });
        }
Esempio n. 6
0
        private async Task BindingLocation()
        {
            labelLocation.Text = "Getting gps"; try
            {
                var locator  = CrossGeolocator.Current;
                var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000);

                if (position == null)
                {
                    labelLocation.Text = "null gps :(";
                    return;
                }

                labelLocation.Text = string.Format("Lat: {0} \nLong: {1}", position.Latitude, position.Longitude);

                var position1         = new Position(position.Latitude, position.Longitude);
                var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position1);

                foreach (var address in possibleAddresses)
                {
                    labelLocation.Text += "\n" + address;
                }
            }
            catch (Exception ex)
            {
                labelLocation.Text = ex.Message;
            }
        }
        // Return current location ({city} {state}) of device
        public async Task <string> GetLocation()
        {
            try {
                // Get Longitude and Latitude of current device location
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy         = 50;
                locator.AllowsBackgroundUpdates = true;

                var position = await locator.GetPositionAsync(timeoutMilliseconds : 10000);

                var geoCoderPosition = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude);

                // Reverse geocoding
                var geocoder = new Geocoder();
                Xamarin.FormsMaps.Init();
                var addresses = await geocoder.GetAddressesForPositionAsync(geoCoderPosition);

                foreach (var address in addresses)
                {
                    string        addressString = address.ToString();
                    List <string> addressParse  = addressString.Split("\n".ToCharArray()).ToList <string>();
                    string        cityState     = Regex.Replace(addressParse[1], @"[\d-]", string.Empty);
                    return(cityState.Trim());
                }
            }
            catch (Exception ex)
            {
                UIAlertView avAlert = new UIAlertView("postion failed", ex.Message, null, "OK", null);
                avAlert.Show();
            }
            return(null);
        }
Esempio n. 8
0
        private async Task<Grid> GetPanel()
        {
            var grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });
            grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });

            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
            grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });

            grid.Children.Add(new Label() { Text = "Current coordinate: " }, 0, 0);


            var position = await GetPosition();
            var longth = position.Longitude;
            var width = position.Latitude;

            grid.Children.Add(new Label() { Text = $"Latitude: {width}; Longitude: {longth}" }, 1, 0);

            Button getCurrentLocationButton = new Button() { Text = "Get current location" };
            getCurrentLocationButton.Clicked += GetCurrentLocationButton_click;

            grid.Children.Add(getCurrentLocationButton, 0, 1);

            Geocoder geoCoder = new Geocoder();

            Position positionAdress = new Position(width, longth);
            IEnumerable<string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(positionAdress);
            string address = possibleAddresses.FirstOrDefault();

            grid.Children.Add(new Label() { Text = address }, 1, 1);

            return grid;
        }
Esempio n. 9
0
        public delivery()
        {
            InitializeComponent();
            geoCoder = new Geocoder();
            var latlong = "";

            map.MapClicked += async(s, arg) =>
            {
                var x = arg.Position.Latitude;
                var y = arg.Position.Longitude;
                latlong = x + "," + y;
                if (!string.IsNullOrWhiteSpace(latlong))
                {
                    string[] coordinates = latlong.Split(',');
                    double?  latitude    = Convert.ToDouble(coordinates[0]);
                    double?  longitude   = Convert.ToDouble(coordinates[1]);

                    if (latitude != null && longitude != null)
                    {
                        Position             position          = new Position(latitude.Value, longitude.Value);
                        IEnumerable <string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);

                        //Geocoder;
                        string address = possibleAddresses.FirstOrDefault();
                        reverseGeocodedOutputLabel.Text = address;
                    }
                }
            };
        }
Esempio n. 10
0
        private async Task <string> ObtenerDireccion(Position position)
        {
            var geo    = new Geocoder();
            var result = await geo.GetAddressesForPositionAsync(position);

            return(result.FirstOrDefault());
        }
        async public Task <string> ReverseGeoCoding(double lat, double lng)
        {
            Geocoder geo = new Geocoder();
            Position p   = new Position(lat, lng);

            try
            {
                string result = "";

                var addresses = await geo.GetAddressesForPositionAsync(p);

                foreach (var address in addresses)
                {
                    result += address;
                }

                string[] index      = result.Split('\n');
                string   newaddress = index[0];

                return(newaddress);
            }
            catch
            {
                return("");
            }
        }
        public PickLocationMapPage()
        {
            InitializeComponent();
            ChooseLocationLabel.Text = AppResources.ChooseLocationLabel;
            DropLocationLabel.Text   = AppResources.DropLocationLabel;
            NextButton.Text          = AppResources.NextButton;
            try
            {
                GetCurrentPosition();
                customMap.PropertyChanged += async(object sender, System.ComponentModel.PropertyChangedEventArgs e) =>
                {
                    var m = (Map)sender;
                    if (m.VisibleRegion != null)
                    {
                        // Debug.WriteLine("Lat: " + m.VisibleRegion.Center.Latitude.ToString() + " Lon:" + m.VisibleRegion.Center.Longitude.ToString());
                        var      pickedposition = m.VisibleRegion.Center;
                        Geocoder gc             = new Geocoder();

                        IEnumerable <string> pickedaddress = await gc.GetAddressesForPositionAsync(pickedposition);

                        address = pickedaddress.First().ToString();
                        MessagingCenter.Send(address, "LocationAddress", pickedposition);
                    }
                };
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 13
0
        async void OnButtonClicked(object sender, EventArgs e)
        {
            geoCoder = new Geocoder();

            var locator1 = CrossGeolocator.Current;

            if (!locator1.IsGeolocationEnabled)
            {
                //GPS is unavailable
                await DisplayAlert("No GPS", "We could not retrieve your location, please make sure you have GPS enabled.", "OK");
            }
            else
            {
                //Retrieve GPS coordinates
                var pos = await locator1.GetPositionAsync(timeoutMilliseconds : 30000);

                if (pos.Longitude != 0.0D || pos.Latitude != 0.0D)//0.0D to check if empty, double can't be 'null'.
                {
                    position = new Position(pos.Latitude, pos.Longitude);

                    //Works like a charm, sometimes.
                    var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);

                    locationLabel.Text = possibleAddresses.First();
                }
                else
                {
                    //GPS is unavailable
                    await DisplayAlert("Time-out", "We could not retrieve your location on time, please try again.", "OK");
                }
            }
        }
Esempio n. 14
0
        private async void SearchBar_SearchButtonPressed(object sender, EventArgs e)
        {
            var positions = await geocoder.GetPositionsForAddressAsync(searchBar.Text);

            var position = positions.FirstOrDefault();

            if (position != null)
            {
                map.MoveToRegion(
                    MapSpan.FromCenterAndRadius(
                        position,
                        Distance.FromMiles(0.2)));

                var addresses = await geocoder.GetAddressesForPositionAsync(position);

                var address = addresses.FirstOrDefault();

                if (address != null)
                {
                    map.Pins.Clear();

                    var pin = new Pin
                    {
                        Type     = PinType.Place,
                        Position = position,
                        Label    = searchBar.Text,
                        Address  = address.Replace("\n", "")
                    };
                    map.Pins.Add(pin);
                }
            }
        }
Esempio n. 15
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            var user    = App.Locator.MainViewModel.User;
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;
            try
            {
                var geoLocation = await locator.GetPositionAsync(5000);

                var pos = new Position(geoLocation.Latitude, geoLocation.Longitude);

                var geo       = new Geocoder();
                var addresses = await geo.GetAddressesForPositionAsync(pos);

                var addr = addresses.First();

                var userAddress = new Address();
                userAddress.AddressText = addr;
                userAddress.Position    = pos;
                user.Address            = userAddress;
            }
            catch (Exception ex)
            {
                this.DisplayAlert("Error", "Error on getting current user location: " + ex.Message, "OK");

                return;
            }
        }
Esempio n. 16
0
        //CheckTurnOnLocation
        public async Task <bool> CheckTurnOnLocation()
        {
            try
            {
                var locator = CrossGeolocator.Current;
                //Task<CrossGeolocator> position = await locator.GetPositionAsync(20000);
                var position = await locator.GetPositionAsync(10000);

                Initial.PositionNow = new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude);


                Geocoder _geoCoder         = new Geocoder();
                var      possibleAddresses = await _geoCoder.GetAddressesForPositionAsync(Initial.PositionNow);

                // foreach (var address in possibleAddresses)
                Initial.PositionName = possibleAddresses.ToList()[0].Replace('\n', ',');
                // LocationText += possibleAddresses.GetEnumerator() + "\n";

                return(true);
            }
            catch
            {
                PushNotication("Bạn phải bật 'Vị Trí' để có thể tiếp tục");
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
                return(false);
            }
            //GetData();
        }
Esempio n. 17
0
        /*
         * GetLocation - View session live for more details.
         */
        public async Task <bool> GetLocation()
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 20;

            var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(1), null, true);

            Geocoder geoCoder;

            geoCoder = new Geocoder();

            var temp = new Position(position.Latitude, position.Longitude);
            var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(temp);

            List <string> listPossibleAddresses = new List <string>();

            foreach (var address in possibleAddresses)
            {
                listPossibleAddresses.Add(address);
            }
            bool change = Verfiy_Location.locationChange(live, position.Latitude, position.Longitude, listPossibleAddresses, database);

            return(change);
        }
Esempio n. 18
0
        async void OnReverseGeocodeButtonClicked(object sender, EventArgs e)
        {
            var locator = CrossGeolocator.Current;

            locator.DesiredAccuracy = 50;

            var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

            var LongitudeLabel = position.Longitude;
            var LatitudeLabel  = position.Latitude;

            inputEntry.Text = Convert.ToString(position.Latitude) + "," + Convert.ToString(position.Longitude);

            if (!string.IsNullOrWhiteSpace(inputEntry.Text))
            {
                var    coordinates = inputEntry.Text.Split(',');
                double?latitude    = Convert.ToDouble(coordinates.FirstOrDefault());
                double?longitude   = Convert.ToDouble(coordinates.Skip(1).FirstOrDefault());

                if (latitude != null && longitude != null)
                {
                    var positionn         = new Position(LatitudeLabel, LongitudeLabel);
                    var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(positionn);

                    foreach (var address in possibleAddresses)
                    {
                        reverseGeocodedOutputLabel.Text += address + "\n";
                    }
                }
            }
        }
Esempio n. 19
0
        async Task SetMap(string destination)
        {
            geoCoder = new Geocoder();
            var position = await CrossGeolocator.Current.GetPositionAsync();

            var currentPosition = new Position(position.Latitude, position.Longitude);
            var Addresses       = await geoCoder.GetAddressesForPositionAsync(currentPosition);

            string fulladdress = "";

            foreach (var address in Addresses)
            {
                fulladdress += address;
            }

            var Destination = destination;

            if (Device.RuntimePlatform == Device.iOS)
            {
                //https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
                Device.OpenUri(new Uri("http://maps.apple.com/?daddr=" + Destination + "&saddr=" + fulladdress));
            }
            else if (Device.RuntimePlatform == Device.Android)
            {
                // opens the 'task chooser' so the user can pick Maps, Chrome or other mapping app
                Device.OpenUri(new Uri("http://maps.google.com/?daddr=" + Destination + "saddr=" + fulladdress));
            }
        }
Esempio n. 20
0
        public async Task GetUserLocation()
        {
            try
            {
                var request  = new GeolocationRequest(GeolocationAccuracy.High);
                var location = await Geolocation.GetLocationAsync(request);

                if (location != null)
                {
                    // getting string address

                    Geocoder             geoCoder          = new Geocoder();
                    Position             p                 = new Position(location.Latitude, location.Longitude);
                    IEnumerable <string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(p);

                    loca = new CurrentLocation(location.Latitude, location.Longitude, possibleAddresses.FirstOrDefault(), DateTime.Now);

                    file = new FileDB();
                    file.saveData(loca);

                    locas = file.getData();
                    LocationList.ItemsSource = locas;
                }
            }
            catch (Exception ex)
            {
            }
        }
        public async Task <String> FindAddressByPosition(Double paramLatitude, Double paramLongitude)
        {
            String ret = null;

            try
            {
                Geocoder coder = new Geocoder();

                Position pos = new Position(paramLatitude, paramLongitude);

                IEnumerable <string> lstPosition = await coder.GetAddressesForPositionAsync(pos);

                if (lstPosition != null)
                {
                    ret = lstPosition.First();

                    if (ret.Length > 0)
                    {
                        ret = ret.Replace("\n", "-");
                    }
                }
                else
                {
                    ret = AppResources.AddressNotFound;
                }
            }
            catch (Exception)
            {
                ret = AppResources.AddressNotFound;
            }

            return(ret);
        }
        private async void FindButton_click(object sender, EventArgs args)
        {
            var content = (Grid)Content;

            var map   = (Map)content.Children[0];
            var panel = (Grid)content.Children[1];

            var entryWidth = (Entry)panel.Children[0];
            var entryLong  = (Entry)panel.Children[1];

            if (double.TryParse(entryWidth.Text, out double width) && double.TryParse(entryLong.Text, out double length))
            {
                Geocoder             geoCoder          = new Geocoder();
                Position             positionAdress    = new Position(width, length);
                IEnumerable <string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(positionAdress);

                string address = possibleAddresses.FirstOrDefault();

                var pos = new Position(width, length);

                Pin pin = new Pin
                {
                    Label    = address,
                    Type     = PinType.Place,
                    Position = pos
                };

                map.Pins.Clear();
                map.Pins.Add(pin);
                map.MoveToRegion(MapSpan.FromCenterAndRadius(pos, Distance.FromMiles(0.7)));
            }
        }
Esempio n. 23
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            var locator = CrossGeolocator.Current;

            var position = await locator.GetPositionAsync();

            var cO = await COLogic.GetCO(position.Latitude, position.Longitude);

            var o3 = await O3Logic.GetO3(position.Latitude, position.Longitude);

            var nO2 = await NO2Logic.GetNO2(position.Latitude, position.Longitude);

            var sO2 = await SO2Logic.GetSO2(position.Latitude, position.Longitude);

            var geoPosition = new Position(position.Latitude, position.Longitude);

            var rawAddress = await geoCoder.GetAddressesForPositionAsync(geoPosition);

            foreach (var address in rawAddress)
            {
                currentLocation.Text += address + "\n";
            }
        }
Esempio n. 24
0
        async Task GetCurrent()
        {
            geoCoder = new Geocoder();
            var position = await CrossGeolocator.Current.GetPositionAsync();

            var currentPosition = new Position(position.Latitude, position.Longitude);
            var Addresses       = await geoCoder.GetAddressesForPositionAsync(currentPosition);

            MapCurrent.IsVisible = false;
            myMap.IsVisible      = true;
            myMap.MoveToRegion(MapSpan.FromCenterAndRadius(currentPosition, Distance.FromKilometers(7)));
            string fulladdress = "";

            foreach (var address in Addresses)
            {
                fulladdress += address;
            }
            var currentcode = await po.GetbyPostcodeAsync(fulladdress);

            List <Library> library = await lib.GetbyPostcodeAsync(3168);

            //test.Text = "We display the top " + library.Count.ToString() + " most close Library of your current position";

            testLogin.IsEnabled     = false;
            testLogin.IsVisible     = false;
            testNoneLogin.IsEnabled = true;
            testNoneLogin.IsVisible = true;

            for (int i = 0; i < library.Count; i++)
            {
                var pin = new CustomPin
                {
                    Pin = new Pin
                    {
                        Type     = PinType.Place,
                        Position = new Position(Double.Parse(library[i].Lat), Double.Parse(library[i].Lon)),
                        Label    = library[i].Name,
                        Address  = library[i].Address
                    }
                };
                myMap.CustomPins = new List <CustomPin> {
                    pin
                };
                myMap.Pins.Add(pin.Pin);
                pin.Pin.Clicked += async(object sender, EventArgs e) =>
                {
                    var p1 = sender as Pin;
                    await SetMap(p1.Address);
                };
            }
            var myPin = new Pin
            {
                Type     = PinType.Generic,
                Position = currentPosition,
                Label    = "Current Location",
                Address  = fulladdress
            };

            myMap.Pins.Add(myPin);
        }
Esempio n. 25
0
        public static async Task <string> GetLocationNameForPosition(double latitude, double longitude)
        {
            string sted = string.Empty;

            try
            {
                var geoCoder          = new Geocoder();
                var geoPos            = new Position(latitude, longitude);
                var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(geoPos);

                if (possibleAddresses.Any())
                {
                    sted = possibleAddresses.First();
                    int newLinePos = sted.IndexOf(Environment.NewLine, StringComparison.CurrentCultureIgnoreCase);
                    if (newLinePos > 0) //removes line 2
                    {
                        sted = sted.Substring(0, newLinePos);
                    }
                    if (sted.Length > 5 && Regex.IsMatch(sted, "^\\d{4}[\" \"]")) //removes zipcode
                    {
                        sted = sted.Substring(5);
                    }
                }
            }
            catch (Exception ex)
            {
                //TODO: Log this
                throw new Exception(ex.Message, ex);
            }
            return(sted);
        }
Esempio n. 26
0
        async void Add_Address_Button(object sender, System.EventArgs e)
        {
            var request  = new GeolocationRequest(GeolocationAccuracy.Medium);
            var location = await Geolocation.GetLocationAsync(request);

            if (location != null)
            {
                Geocoder      geocoder    = new Geocoder();
                List <string> addresslist = new List <string>();

                var position  = new Position(location.Latitude, location.Longitude);
                var addresses = await geocoder.GetAddressesForPositionAsync(position);

                foreach (var address in addresses)
                {
                    addresslist.Add(address);
                }

                var x = await DisplayAlert("Is this your location", addresslist[0], "Yes", "No");

                if (x)
                {
                    user.Address = addresslist[0];
                    await App.UserManager.UpdateUser(user);
                    await PopulateUserPage(true);
                }
                else
                {
                    await Navigation.PushPopupAsync(new AddUserAddressPage(user));
                    await PopulateUserPage(true);
                }
            }
        }
Esempio n. 27
0
        async void OnReverseGeocodeButtonClicked(object sender, EventArgs e)
        {
            var latlong2 = "16.43307340526658, 102.8255601788635";

            map.MapClicked += (s, arg) =>
            {
                var x = arg.Position.Latitude;
                var y = arg.Position.Longitude;
                latlong2 = x + "," + y;
            };
            if (!string.IsNullOrWhiteSpace(latlong2))
            {
                string[] coordinates = latlong2.Split(',');
                double?  latitude    = Convert.ToDouble(coordinates[0]);
                double?  longitude   = Convert.ToDouble(coordinates[1]);

                if (latitude != null && longitude != null)
                {
                    Position             position          = new Position(latitude.Value, longitude.Value);
                    IEnumerable <string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(position);

                    IEnumerable <Position> possibleAddresses2 = await geoCoder.GetPositionsForAddressAsync(possibleAddresses.FirstOrDefault());

                    //Geocoder;
                    string address = possibleAddresses.FirstOrDefault();
                    reverseGeocodedOutputLabel.Text = address;
                }
            }
        }
Esempio n. 28
0
        public static async Task <string> SetCurrentLocation()
        {
            GlobalSetting.position = new Position(17.456508, 78.412616);            //default location

            ILocation loc = DependencyService.Get <ILocation>();

            loc.locationObtained += (object ss, ILocationEventArgs ee) =>
            {
                GlobalSetting.position = new Position(ee.lat, ee.lng);
            };
            loc.ObtainMyLocation();

            var geocoder = new Geocoder();

            var addresses = await geocoder.GetAddressesForPositionAsync(GlobalSetting.position);

            //{System.Linq.Enumerable.WhereSelectArrayIterator<CoreLocation.CLPlacemark,string>}

            foreach (var address in addresses)
            {
                var arrAddress = address.Split(new char[] { '\n' });

                return(arrAddress[1]);
            }

            return(null);
        }
Esempio n. 29
0
        public async Task GPS()
        {
            try
            {
                var request  = new GeolocationRequest(GeolocationAccuracy.Medium);
                var location = await Geolocation.GetLocationAsync(request);


                Geocoder geoCoder = new Geocoder();


                IEnumerable <string> possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Position(location.Latitude, location.Longitude));

                string result  = possibleAddresses.FirstOrDefault();
                string address = result.Split('\n')[0].Trim();
                string city    = result.Split('\n')[1].Trim();

                LocationInfo.Adresa = address;
                LocationInfo.Grad   = city;
            }
            catch (Exception ex)
            {
                await DisplayAlert("Upozorenje", ex.Message, "Uredu");

                LocationInfo.Adresa = " ";
                LocationInfo.Grad   = " ";
            }
        }
Esempio n. 30
0
        public async Task <GeocodeAddressResponse> FindAddressAsync(GeocodeAddressRequest request)
        {
            var position = new Position(request.Location.Latitude, request.Location.Longitude);
            var result   = await _geoCoder.GetAddressesForPositionAsync(position).ConfigureAwait(false);

            return(new GeocodeAddressResponse(result.ToList()));
        }