private void Initialize() { var configBuilder = new ConfigurationBuilder().AddJsonFile(_configFileName); var config = configBuilder.Build(); geocodingClient = new GeocodingClient <GeocodingResponse>(new ApiClient(new ApiContext { OutputFormat = config["GoogleApi:OutputFormat"], ApiKey = config["GoogleApi:GeocodingApiKey"], HostName = config["GoogleApi:HostName"], Path = config["GoogleApi:Path"], Protocol = config["GoogleApi:Protocol"], ApiMethod = config["GoogleApi:GeocodingMethod"] }, new RateGate(1, TimeSpan.FromSeconds(5)), new JsonResponseConverter())); distanceMatrixClient = new DistanceMatrixClient <DistanceMatrixResponse>(new ApiClient(new ApiContext { OutputFormat = config["GoogleApi:OutputFormat"], ApiKey = config["GoogleApi:DistanceMatixApiKey"], HostName = config["GoogleApi:HostName"], Path = config["GoogleApi:Path"], Protocol = config["GoogleApi:Protocol"], ApiMethod = config["GoogleApi:DistanceMatrixMethod"] }, new RateGate(1, TimeSpan.FromSeconds(5)), new JsonResponseConverter())); }
void OnTextChange(object sender, TextChangedEventArgs e) { string text = e.Text.ToString(); if (string.IsNullOrWhiteSpace(text)) { return; } ContentView.ShowTable(); text = ContentView.Field.Text; GeocodingClient.MakeRequest(text, delegate { RunOnUiThread(delegate { ContentView.UpdateList(GeocodingClient.Addresses); }); }); }
void OnEditingEnded(bool geocode) { ContentView.CloseKeyboard(); ContentView.HideTable(); if (geocode) { string text = ContentView.Field.Text; GeocodingClient.MakeRequest(text, delegate { if (GeocodingClient.HasAddress) { GeocodingResult result = GeocodingClient.Addresses[0]; ShowResult(result); } }); } ContentView.ClearInput(); }
/// <summary> /// The main entry-point to the application. /// </summary> /// <param name="args">The arguments passed to the application.</param> internal static void Main(string[] args) { var client = new GeocodingClient(); if (args != null && args.Length == 1) { client.ApiKey = args[0]; } string coordinates = null; while (true) { Console.Write("Coordinates: "); coordinates = Console.ReadLine(); if (string.IsNullOrEmpty(coordinates)) { break; } string[] parts = coordinates.Split(','); if (parts.Length != 2) { continue; } double latitude; double longitude; if (!double.TryParse(parts[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out latitude)) { continue; } if (!double.TryParse(parts[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out longitude)) { continue; } CoordinateLookup result; try { result = client.LookupAsync(latitude, longitude).Result; } catch (Exception ex) { Console.Error.WriteLine(); Console.Error.WriteLine("Failed to look up coordinates: {0}", ex.ToString()); continue; } Console.WriteLine(); Console.WriteLine("Result for {0}:", coordinates); Console.WriteLine(); if (result == null) { Console.WriteLine(" Not found."); } else { Console.WriteLine(" Lat/Long: {0:N2},{1:N2}", latitude, longitude); Console.WriteLine(" City: {0}", result.City); Console.WriteLine(" Postal Code: {0}", result.PostalCode); Console.WriteLine(" Region: {0}", result.RegionCode); Console.WriteLine(" Country: {0}", result.CountryCode); } Console.WriteLine(); } }
public APIQueryGeocode() { _logger = new DebugLogger(); _client = new GeocodingClient(new DebugLogger()); }
protected override void SetOfflineMode() { GeocodingClient.SetOfflineMode(); }
public GeocodingTests() { _client = new GeocodingClient(new DebugLogger()); }