async Task <float> CalculatePollution(List <Position> pollutionPoints, bool main = false) { float overall = 0, max = 0; if (pollutionPoints.Count > 0) { List <List <string> > list = new List <List <string> >(); for (int i = 0; i < pollutionPoints.Count; i++) { List <string> point = new List <string>(); point.Add(pollutionPoints[i].Latitude.ToString("F6")); point.Add(pollutionPoints[i].Longitude.ToString("F6")); list.Add(point); } PollutionRequest request = new PollutionRequest() { RAD = 50, PAIRS = list }; var result = await rest.GetPollution(JsonConvert.SerializeObject(request)); if (result != null) { int maxIndex = 0; if (result.val.Count >= 5) { for (int index = 2; index < result.val.Count - 2; index++) { float subTotal = 0; for (int j = index - 2; j < index + 2; j++) { subTotal += (float)Convert.ToDouble(result.val[j]); } if (subTotal > max) { max = subTotal; maxIndex = index; peak = max; } overall += (float)Convert.ToDouble(result.val[index]); } overall /= result.val.Count; double lat, lng; lat = Convert.ToDouble(result.lat[maxIndex]); lng = Convert.ToDouble(result.lon[maxIndex]); hotspot = new Position(lat, lng); } } } return(overall); }