public IHttpActionResult GetDroneInfo(double?lat = null, double?lng = null) { if (lat == null || lng == null) { return(BadRequest("Missing Parametars")); } EnviromentInfoViewModel model = new EnviromentInfoViewModel(); model.Coordinate = new Coordinate() { Latitude = Double.Parse(lat.ToString()), Longitude = Double.Parse(lng.ToString()) }; String yahooApi = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places%20where%20text%3D%22(" + lat + "%2C" + lng + ")%22)%20and%20u%3D'c'&format=json&callback="; String googleElevationApiKey = "https://maps.googleapis.com/maps/api/elevation/json?locations=" + lat + "," + lng + "&key=AIzaSyDTkIcb_EL4fQFTQMe9DA1N5gyQHgmCRGM"; using (WebClient wc = new WebClient()) { var yahooWeatherData = wc.DownloadString(yahooApi); dynamic weatherResult = JsonConvert.DeserializeObject(yahooWeatherData); JObject result = weatherResult.query.results; if (result == null) { return(InternalServerError()); } ; JObject wind = weatherResult.query.results.channel.wind; model.Wind = wind.ToObject <Wind>(); model.Wind.directionSymbol = Helper.GetWindDirection(model.Wind.direction); JObject unit = weatherResult.query.results.channel.units; model.Unit = unit.ToObject <Unit>(); JObject location = weatherResult.query.results.channel.location; model.Location = location.ToObject <Location>(); JObject atmosphere = weatherResult.query.results.channel.atmosphere; model.Atmosphere = atmosphere.ToObject <Atmosphere>(); JObject item = weatherResult.query.results.channel.item.condition; model.Condition = item.ToObject <Condition>(); ConditionsService conditionsService = new ConditionsService(); model.Condition.text = conditionsService.GetId(model.Condition.text); var googleData = wc.DownloadString(googleElevationApiKey); dynamic elevationResult = JsonConvert.DeserializeObject(googleData); JObject elevation = elevationResult.results[0]; model.Elevation = elevation.ToObject <Elevation>(); } return(Ok(model)); }
public string GetConditionType(string condition = "sunny") { string result = ""; ConditionsService conditionsService = new ConditionsService(); result = conditionsService.GetId(condition); return(result); }