public async Task SearchForPlaces(double lat, double lng, string query) { if (IsBusy) { return; } try { IsBusy = true; var requestUri = string.Format(SearchQueryUrl, query, lat.ToString(CultureInfo.InvariantCulture), lng.ToString(CultureInfo.InvariantCulture), Keys.GoogleAPIKey); var client = new HttpClient(); var result = await client.GetStringAsync(requestUri); var queryObject = JsonConvert.DeserializeObject <SearchQueryResult>(result); if (queryObject?.Places != null) { Places.ReplaceRange(queryObject.Places.Select(p => new Coffee { Latitude = p.Latitude, Longitude = p.Longitude, Name = p.Name, Stars = (float)p.Rating })); } } catch (Exception ex) { Console.WriteLine("Unable to query" + ex); } finally { IsBusy = false; } }
public async Task LoadCoffees() { if (IsBusy) { return; } try { IsBusy = true; var coffees = await AzureService.Instance.GetCoffees(); Places.ReplaceRange(coffees); } catch (Exception ex) { Console.WriteLine("Unable to load" + ex); } finally { IsBusy = false; } }