/// <summary> /// Geocoding is the process of converting addresses /// (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic /// coordinates(like latitude 37.423021 and longitude -122.083739), which you /// can use to place markers or position the map. /// </summary> /// <param name="address"> /// The address to geocode. /// </param> /// <param name="components"> /// A component filter for which you wish to obtain a /// geocode, for example: {"administrative_area": "TX","country": "US"} /// </param> /// <param name="bounds"> /// The bounding box of the viewport within which to bias geocode /// results more prominently. /// </param> /// <param name="region"> /// The region code, specified as a ccTLD ("top-level domain") two-character value. /// </param> /// <param name="language"> /// The language in which to return results. /// </param> /// <returns>Geocoding results</returns> public GeocodeResponse Geocode(string address = null, ComponentsFilter components = null, ViewportBoundingBox bounds = null, string region = null, string language = null) { // Assign query params var queryParams = new QueryParams(); // Address if (address != null) { queryParams["address"] = address; } // Components if (components != null) { queryParams["components"] = Converter.Components(components); } // Bounds if (bounds != null) { queryParams["bounds"] = Converter.Bounds(bounds); } // Regions if (region != null) { queryParams["region"] = region; } // Language if (language != null) { queryParams["language"] = language; } // Get API response result var response = Client.APIGet <GeocodeResponse>("/maps/api/geocode/json", queryParams); // Return it return(response); }
/// <summary> /// Converts a lat/lon bounds to a comma- and pipe-separated string. /// /// Accepts two representations: /// /// 1) string: pipe-separated pair of comma-separated lat/lon pairs. /// 2) dict with two entries - "southwest" and "northeast". See convert.latlng /// for information on how these can be represented. /// /// For example: /// /// sydney_bounds = { /// "northeast" : { /// "lat" : -33.4245981, /// "lng" : 151.3426361 /// }, /// "southwest" : { /// "lat" : -34.1692489, /// "lng" : 150.502229 /// } /// } /// /// convert.bounds(sydney_bounds) /// # '-34.169249,150.502229|-33.424598,151.342636' /// /// </summary> /// <param name="bounds"></param> /// <returns>Result string</returns> public static string Bounds(ViewportBoundingBox bounds) { return($"{bounds.Southwest.Latitude},{bounds.Southwest.Longitude}" + $"|{bounds.NorthEast.Latitude},{bounds.NorthEast.Longitude}"); }