public async void GetPlaces(string searchText) { try { List <string> dictCities = new List <string>(); string url = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" + searchText + "&types=geocode&key=AIzaSyCAW0qqikPYbOKLu_aobSw04z1Dnfhgpv4"; wsGooglePlaces _objUserData = await CommonLib.getGooglePlaces(url); if (_objUserData != null && _objUserData.predictions.Count > 0) { lstViewPlaces.ItemsSource = null; lstViewPlaces.ItemsSource = _objUserData.predictions; } else if (_objUserData == null) { await DisplayAlert("", "Internet seems to be down.", "OK"); } } catch { } finally { } }
public async void GetPlaces(string searchText) { try { List <string> dictCities = new List <string>(); string url = "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" + searchText + "&types=geocode&key=AIzaSyCbuKat-iBg90bfM8G0bytzVTdIThmgv94"; wsGooglePlaces _objUserData = await getGooglePlaces(url); if (_objUserData != null && _objUserData.predictions.Count > 0) { Items.Clear(); Items = new ObservableCollection <string>(); foreach (var item in _objUserData.predictions) { Items.Add(item.description); } } } catch { } finally { } }
public static async Task <wsGooglePlaces> getGooglePlaces(string url) { wsGooglePlaces objData = new wsGooglePlaces(); try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(url); TimeSpan time = new TimeSpan(0, 0, 20); client.Timeout = time; var result = await client.GetAsync(url); var place = result.Content.ReadAsStringAsync().Result; objData = JsonConvert.DeserializeObject <wsGooglePlaces>(await result.Content.ReadAsStringAsync()); } } catch (Exception ex) { } return(objData); }