Beispiel #1
0
        public async Task <IActionResult> Zip(string zip)
        {
            ZipToLatLon modelVar = new ZipToLatLon();
            var         client   = new HttpClient();

            client.BaseAddress = new Uri("https://api.zip-codes.com");
            client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; GrandCircus/1.0)");
            var modifiedEndPoint = "ZipCodesAPI.svc/1.0/QuickGetZipCodeDetails/" + zip + "?key=Y4P999GSKSNZ0PH2IJEF";
            var response         = await client.GetAsync(modifiedEndPoint);

            var LatLon = await response.Content.ReadAsAsync <ZipToLatLon>();

            modelVar.Latitude  = LatLon.Latitude;
            modelVar.Longitude = LatLon.Longitude;



            return(RedirectToAction("Forecast", "Home", modelVar));
        }
Beispiel #2
0
        public async Task <IActionResult> Forecast(ZipToLatLon modelVar, string lat, string lon)
        {
            if (lat == null && lon == null)
            {
                lat = modelVar.Latitude;
                lon = modelVar.Longitude;
            }


            var client = new HttpClient();

            client.BaseAddress = new Uri("https://forecast.weather.gov");
            client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (compatible; GrandCircus/1.0)");
            var modifiedEndPoint = "MapClick.php?lat=" + lat + "&lon=" + lon + "&FcstType=json";
            var response         = await client.GetAsync(modifiedEndPoint);

            var forecast = await response.Content.ReadAsAsync <Weather>();

            return(View(forecast));
        }