private void GeocodeCsvAddressesFrom(string path, string key) { var amWebClient = new CookieWebClient(); var amBasePath = new ApplicationBasePath( protocolPrefix: "https://", site: "atlas.microsoft.com", applicationPath: "/"); var amClient = new AzureMapsClient( webClient: amWebClient, basePath: amBasePath, subscriptionKey: key); int geocoded = 0; int alreadyGeocode = 0; var addresses = LoadCsvAddresses.LoadFrom(path); foreach (var address in addresses) { if (address.Latitude == null || address.Longitude == null || address.Latitude == 0 || address.Longitude == 0) { var coordinates = new AzureMapsmGeocodeAddress(view, amClient) .Geocode(address); address.Latitude = coordinates.Latitude; address.Longitude = coordinates.Longitude; geocoded++; } else { alreadyGeocode++; } } view.AppendResultText($"\nTotal Addresses: {(geocoded + alreadyGeocode)}"); view.AppendResultText($"\nGeocoded: {geocoded}"); view.AppendResultText($"\nAlready Geocoded (Skipped): {alreadyGeocode}"); var newPath = view.GetFileNameToSaveAs(path, "csv"); if (string.IsNullOrWhiteSpace(newPath)) { // Cancelled view.AppendResultText($"\nGeocoding not saved."); return; } LoadCsvAddresses.SaveTo(addresses, newPath); view.AppendResultText($"\nGeocoding saved to {newPath}"); }