/** * Gets all the groceries and supermarkets for a given location */ public async Task <IEnumerable <Supermarket> > GetSupermarketsFromLocation(GeoCoordinate location) { List <Supermarket> supermarkets = new List <Supermarket>(); GooglePlacesObject rootResults = await _googleMapsApiService.GetSupermarkets(location); if (rootResults != null) { List <GoogleSupermarket> googleSupermarketList = rootResults.results; if (googleSupermarketList.Count == 0) { throw new Exception("No results found"); } else { Supermarket supermarket; GeoCoordinate currentLocation; foreach (GoogleSupermarket googleSupermarket in googleSupermarketList) { currentLocation = new GeoCoordinate(googleSupermarket.geometry.location.lat, googleSupermarket.geometry.location.lng); supermarket = new Supermarket() { id = googleSupermarket.id, name = googleSupermarket.name, address = googleSupermarket.vicinity, location = currentLocation, distance = LocationUtils.CalculateDistance(location, currentLocation) }; supermarkets.Add(supermarket); } ; } return(supermarkets.OrderBy(x => x.distance).ToList()); } else { return(supermarkets); } }