public JsonResult GetLocationFromZip(string zip, int idcountry) { var country = _countryOrRegionService.FirstOrDefault(o => o.Id == idcountry); string namecountry = ""; if (country == null) { namecountry = ""; } else { namecountry = country.Name; } var url = "http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:" + zip + "|country:" + namecountry; var client = new WebClient(); //client.Headers.Add("User-Agent", "Nobody"); //my endpoint needs this... var response = client.DownloadString(new Uri(url)); var data = JsonConvert.DeserializeObject <GoogleGetLocation>(response); // Display data read from web site return(Json(data, JsonRequestBehavior.AllowGet)); }
public JsonResult GetNameCountryOrRegion(int id) { var data = _countryOrRegionService.FirstOrDefault(o => o.Id == id); return(Json(data, JsonRequestBehavior.AllowGet)); }