private async void AddressListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) { Location location = (Location)e.SelectedItem; if (location == null) { return; } this.SearchEntry.Text = location.Address; this.SearchEntry.Unfocus(); if (!CrossConnectivity.Current.IsConnected) { DependencyService.Get <IMessageHelper>().LongAlert($"Gagal memuat. Periksa kembali koneksi internet anda."); return; } this.MyMap.Pins.Clear(); location = await AutoCompleteLocationService.GetPlace(location.Place_ID); Position position = new Position( location.Latitude, location.Longitude); Pin locatedPin = new Pin() { Type = PinType.Place, Label = this.SearchEntry.Text, Address = this.SearchEntry.Text, Position = position, Flat = true }; this.MyMap.Pins.Add(locatedPin); this.MyMap.MoveToRegion( MapSpan.FromCenterAndRadius( position, Distance.FromMeters( MAP_SPAN_RADIUS))); var pins = await CreatePins(position); foreach (Pin pin in pins) { this.MyMap.Pins.Add(pin); } this.AddressListView.SelectedItem = null; }
private async void OnSearchEntryTextChanged(object sender, TextChangedEventArgs e) { if (String.IsNullOrEmpty(e.NewTextValue) || String.IsNullOrWhiteSpace(e.NewTextValue) || this.SearchEntry.Text.Length < MINIM_SEARCH_TEXT) { this.ViewModel.AddressList = new List <Location>(); return; } if (!CrossConnectivity.Current.IsConnected) { return; } AutoCompleteLocationResult results = null; try { results = await AutoCompleteLocationService.GetPlaces(e.NewTextValue); } catch (Exception ex) { await this.DisplayAlert("Error", ex.Message, "OK"); this.ViewModel.AddressList = new List <Location>(); return; } if (results == null) { this.ViewModel.AddressList = new List <Location>(); return; } var newAddressList = new List <Location>(); foreach (AutoCompleteLocation autoCompleteLocation in results.AutoCompletePlaces) { Location location = new Location() { Address = autoCompleteLocation.Description, Place_ID = autoCompleteLocation.Place_ID }; newAddressList.Add(location); } this.ViewModel.AddressList = newAddressList; }
private async void OnSearchEntryCompleted(object sender, EventArgs e) { this.SearchEntry.Unfocus(); if (String.IsNullOrEmpty(this.SearchEntry.Text) || String.IsNullOrWhiteSpace(this.SearchEntry.Text)) { return; } if (!CrossConnectivity.Current.IsConnected) { DependencyService.Get <IMessageHelper>().LongAlert($"Gagal memuat. Periksa kembali koneksi internet anda."); return; } AutoCompleteLocationResult results = null; try { results = await AutoCompleteLocationService.GetPlaces(this.SearchEntry.Text); } catch (Exception ex) { await this.DisplayAlert("Error", ex.Message, "OK"); return; } if (results == null) { await this.DisplayAlert("Lokasi Tidak Ditemukan", "Geocoder tidak dapat menemukan lokasi yang anda tuju.", "OK"); return; } this.MyMap.Pins.Clear(); Location location = await AutoCompleteLocationService.GetPlace(results.AutoCompletePlaces.First().Place_ID); Position position = new Position( location.Latitude, location.Longitude); Pin locatedPin = new Pin() { Type = PinType.Place, Label = this.SearchEntry.Text, Address = this.SearchEntry.Text, Position = position, Flat = true }; this.MyMap.Pins.Add(locatedPin); this.MyMap.MoveToRegion( MapSpan.FromCenterAndRadius( position, Distance.FromMeters( MAP_SPAN_RADIUS))); var pins = await CreatePins(position); foreach (Pin pin in pins) { this.MyMap.Pins.Add(pin); } }