public void GetLatitudeLongitude(string postCode, out double?latitude, out double?longitude) { var client = new PostcodesIOClient(); var result = client.Lookup(postCode); latitude = result.Latitude; longitude = result.Longitude; }
public async Task <bool> ValidateAsync(string postcode) { PostcodesIOClient client = new PostcodesIOClient(); var result = await client.ValidateAsync(postcode); return(result); }
public async Task <IEnumerable <string> > AutoCompleteAsync(string postcode) { PostcodesIOClient client = new PostcodesIOClient(); var result = await client.AutocompleteAsync(postcode); return(result); }
public static DbGeography Lookup(string postcode) { PostcodesIOClient client = new PostcodesIOClient(); var postcodeLookup = client.Lookup(postcode); // use the GeoUtils class to create a DbGeography object to represent the point. return(GeoUtils.CreatePoint(postcodeLookup.Latitude, postcodeLookup.Longitude)); }
public void Setup() { _client = new PostcodesIOClient(); _lookups = new[] { new ReverseGeocodeQuery { Latitude = 51.2452924089757, Longitude = -0.58231794275613 }, new ReverseGeocodeQuery { Latitude = 51.2571984465953, Longitude = -0.567549033067429 } }; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { PostcodesIOClient client = new PostcodesIOClient(); var result = client.Validate(value as string); if (result) { return(ValidationResult.Success); } return(new ValidationResult("The postcode given is not valid.")); }
public IHttpActionResult Get() { try { var list = new List <Map>(); var data = File.ReadAllLines($"{PathConstant.Path}\\LatitudeLongitude.csv"); list = data.Skip(1) .Select(t => t.Split(',')) .Select(split => new Map { Latitude = Convert.ToDouble(split[0]), Longitude = Convert.ToDouble(split[1]) }).ToList(); var postcodeList = GetPostcodes(); var count = postcodeList.Count() / 100; var chunks = ChunkBy(postcodeList.ToList(), count); var client = new PostcodesIOClient(); foreach (var chunk in chunks) { var bulkResult = client.BulkLookup(chunk); list.AddRange(from item in bulkResult where item.Result != null select new Map { Latitude = Convert.ToDouble(item.Result.Latitude), Longitude = Convert.ToDouble(item.Result.Longitude) }); } // write to file - results.json SerializeToFile(list); return(Ok(list)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IHttpActionResult> Register(AddBusinessRequest addBusinessRequest) { try { ApplicationDbContext context = new ApplicationDbContext(); var wm = context.Users.FirstOrDefault(user => user.Email == "*****@*****.**"); PostcodesIOClient client = new PostcodesIOClient(); var t = client.Random(); var bt = context.BusinessTypes.OrderBy(r => Guid.NewGuid()).Take(1).FirstOrDefault(); Business business = new Business(); business.Postcode = t.Postcode; business.Location = GeoUtils.CreatePoint(t.Latitude, t.Longitude); business.Users.Add(new BusinessUser() { User = wm }); business.BusinessType = bt; business.Name = "Webmaster's " + bt.Name + " [" + t.Postcode + "]"; context.Businesses.Add(business); context.SaveChanges(); } catch (Exception exception) { return(BadRequest(exception.Message)); } return(Ok()); }
public void Setup() { _client = new PostcodesIOClient(); }
public static async Task <IEnumerable <string> > AutocompleteAsync(this PostcodesIOClient client, string postcode) { return(await Task.Run(() => client.Autocomplete(postcode))); }
public static async Task <bool> ValidateAsync(this PostcodesIOClient client, string postcode) { return(await Task.Run(() => client.Validate(postcode))); }