public static BikeTheft ParseCSVRow(string[] row) { TextInfo format = new CultureInfo("nl-NL", false).TextInfo; string ID = row[0]; string color = format.ToTitleCase(row[24].ToLower()); string brand = format.ToTitleCase(row[22].ToLower()); DateTime dateTime = DateTime.ParseExact(row[11], "dd-MM-yy", CultureInfo.InvariantCulture); string street = format.ToTitleCase(row[9].ToLower()); GoogleLocation location = GoogleGeocodeAPI.GetStreetAndDistrict(street + " Rotterdam"); return(new BikeTheft(ID, location.Street, location.District, brand, color, dateTime)); }
public static BikeContainer ParseCSVRow(string[] row) { TextInfo format = new CultureInfo("nl-NL", false).TextInfo; string ID = row[0]; DateTime dateTime = DateTime.ParseExact(row[32], "dd-MM-yyyy", CultureInfo.InvariantCulture); Double latCoord = double.Parse(row[18]); Double longCoord = double.Parse(row[19]); string street = format.ToTitleCase(row[9].ToLower()); GoogleLocation location = GoogleGeocodeAPI.GetStreetAndDistrict(street + " Rotterdam"); if (location.Validate()) { return(new BikeContainer(ID, dateTime, location.Street, location.District, latCoord, longCoord)); } return(null); }
public static GoogleLocation GetStreetAndDistrict(string street) { GoogleLocation location = new GoogleLocation(); GoogleGeocodeAPI api = new GoogleGeocodeAPI(); Console.WriteLine("Query Google: " + street); api.Request(street); try { JObject json = api.Result; JToken results = json.SelectToken("results").First().SelectToken("address_components"); foreach (JToken result in results) { foreach (JToken types in result.SelectToken("types")) { string type = types.Value <string>(); switch (type) { case "route": location.Street = result.SelectToken("long_name").Value <string>(); break; case "sublocality": location.District = result.SelectToken("long_name").Value <string>(); break; } } } } catch (Exception) { } return(location); }