/// <summary> /// Method used to prepare the additional (and optional) field components of our query, for things like Census or School district fields. /// </summary> /// <param name="fieldSettings">Our field settings object used to determine which additional data fields we want to query.</param> /// <returns>A formatted string which will be appended to the URL when hitting Geocodio.</returns> public string PrepareDataFieldsQueryString(GeocodioDataFieldSettings fieldSettings) { var fields = new List <string>(); foreach (var fieldKey in GeocodioDataFieldSettings.ValidGeocodioFields) { if (fieldSettings.GetFieldQueryStatus(fieldKey)) { fields.Add(fieldKey); } } if (fields.Count == 0) { //No fields to query, give 'em an empty string! return(""); } else { return("&fields=" + String.Join(",", fields)); } }
/// <summary> /// Method used to batch forward geocode a bunch of addresses. /// </summary> /// <param name="inputAddresses">A list of address strings.</param> /// <param name="fieldSettings">Our field settings object used to determine which additional data fields we want to query.</param> /// <returns>The results returned from Geocodio.</returns> public async Task <BatchForwardGeoCodeResult> ForwardGeocodeAsync(List <string> inputAddresses, GeocodioDataFieldSettings fieldSettings) { string fieldQueryString = this.PrepareDataFieldsQueryString(fieldSettings); string jsonDataString = JsonConvert.SerializeObject(inputAddresses); string responseData = await BatchForwardGeocodeWebRequest(jsonDataString, fieldQueryString); BatchForwardGeoCodeResult results = JsonConvert.DeserializeObject <BatchForwardGeoCodeResult>(responseData); return(results); }
/// <summary> /// Method used to forward geocode a single address. /// </summary> /// <param name="addressToGeocode">The address we want to forward geocode.</param> /// <param name="fieldSettings">Our field settings object used to determine which additional data fields we want to query.</param> /// <returns>The results returned from Geocodio.</returns> public async Task <BatchForwardGeoCodeResult> ForwardGeocodeAsync(string addressToGeocode, GeocodioDataFieldSettings fieldSettings) { string fieldQueryString = this.PrepareDataFieldsQueryString(fieldSettings); string responseData = await SingleForwardGeocodeWebRequest(addressToGeocode, fieldQueryString); ForwardGeoCodeResult result = JsonConvert.DeserializeObject <ForwardGeoCodeResult>(responseData); //Wrap result from GeoCodio in BatchForwardGeocodeResult because we always want to return a BatchForwardGeoCodeResult BatchForwardGeoCodeRecord record = new BatchForwardGeoCodeRecord(addressToGeocode, result); return(new BatchForwardGeoCodeResult(new BatchForwardGeoCodeRecord[] { record })); }
/// <summary> /// Method which handles reverse geo-coding a list of lat-long strings in deciaml degress format i.e. "48.434325, -76.434543" /// </summary> /// <param name="inputAddresses">Our list of points to reverse geo-code. Strings in deciaml degress format i.e. "48.434325, -76.434543"</param> /// <param name="fieldSettings">Our field settings object used to determine which additional data fields we want to query.</param> /// <returns>The results from Geocodio.</returns> public async Task <BatchReverseGeoCodingResult> ReverseGeocodeAsync(List <string> inputAddresses, GeocodioDataFieldSettings fieldSettings) { string fieldsQuery = this.PrepareDataFieldsQueryString(fieldSettings); string jsonPostData = JsonConvert.SerializeObject(inputAddresses); string json = await BatchReverseGeocodeWebRequest(jsonPostData, fieldsQuery); BatchReverseGeoCodingResult result = JsonConvert.DeserializeObject <BatchReverseGeoCodingResult>(json); return(result); }
/// <summary> /// Method used to reverse geo-code a single lat-long string in deciaml degress format i.e. "48.434325, -76.434543" /// </summary> /// <param name="latLong">Our point to reverse geo-code. String in deciaml degress format i.e. "48.434325, -76.434543"</param> /// <param name="fieldSettings">Our field settings object used to determine which additional data fields we want to query.</param> /// <returns>The results from Geocodio.</returns> public async Task <BatchReverseGeoCodingResult> ReverseGeocodeAsync(string latLong, GeocodioDataFieldSettings fieldSettings) { string fieldQueryString = this.PrepareDataFieldsQueryString(fieldSettings); string json = await SingleReverseGeocodeWebRequest(latLong, fieldQueryString); ReverseGeoCodeResult result = JsonConvert.DeserializeObject <ReverseGeoCodeResult>(json); BatchReverseGeoCodeResponse response = new BatchReverseGeoCodeResponse(latLong, result); return(new BatchReverseGeoCodingResult(new BatchReverseGeoCodeResponse[] { response })); }