/// <summary> /// Sample showing how to use the geocoder in as simple a manner as possible. /// The sample demonstrates the 'round robin' approach to geocoder selection (first Bing will be used, then Google). /// </summary> /// <returns>A <see cref="Task"/> that should be awaited.</returns> internal async Task ExecuteAsync() { // Define the API keys for the geocoders we'll be using. var geocoderSettings = new List <GeocoderSettings> { new GeocoderSettings { ApiKey = "Your Bing API key (best practice is to put this in a config file, not in source)", GeocoderName = Services.GeocoderNames.Bing }, new GeocoderSettings { ApiKey = "Your Google API key (best practice is to put this in a config file, not in source)", GeocoderName = Services.GeocoderNames.Google }, }; // Instead of doing 'var g = new GeocodeManager' we use a factory method which initialises the library. var geocodeManager = GeocodeManager.Create(geocoderSettings); // This first lookup will be handled by Bing (unless it fails to resolve the address, which will then fail over to Google). var firstResult = await geocodeManager.GeocodeAddressAsync("10 Downing St., London, UK"); Console.WriteLine($"Result of first lookup, used {firstResult.GeocoderId}, status of {firstResult.Status} with {firstResult.Locations.Count} results."); foreach (var foundLocation in firstResult.Locations) { Console.WriteLine($"Address of {foundLocation.FormattedAddress} has a location of {foundLocation.Location.Latitude} / {foundLocation.Location.Longitude}"); } // The following lookup then uses the other geocoder service. var secondResult = await geocodeManager.GeocodeAddressAsync("The Acropolis, Greece"); Console.WriteLine($"Result of second lookup, used {secondResult.GeocoderId}, status of {secondResult.Status} with {secondResult.Locations.Count} results."); foreach (var foundLocation in secondResult.Locations) { Console.WriteLine($"Address of {foundLocation.FormattedAddress} has a location of {foundLocation.Location.Latitude} / {foundLocation.Location.Longitude}"); } }
public void Self_registration_succeeds_with_empty_list() { var geocoderSettings = new List <GeocoderSettings>(); var geocodeManager = GeocodeManager.Create(geocoderSettings); Assert.NotNull(geocodeManager); }
public GeocodeService(string key, GeocoderNames geocoder) { var geocoderSettings = new List <GeocoderSettings> { new GeocoderSettings { ApiKey = key, GeocoderName = geocoder }, }; geocodeManager = GeocodeManager.Create(geocoderSettings); }
public void Self_registration_does_not_succeed_with_null_list() { var geocodeManager = GeocodeManager.Create(null); Assert.Null(geocodeManager); }