Example #1
0
 public (double longitude, double latitude) GetCoordinates(NullableLocationDto location)
 {
     if (!string.IsNullOrEmpty(location.Street) && location.StreetNumber.HasValue && location.PostalCode.HasValue)
     {
         var queryString = $"?q={ location.StreetNumber }+{ Regex.Replace(location.Street.Trim(), @"\s+", "+") }+&postcode={ location.PostalCode }";
         return(GetCoordinatesFromUrl(AppSettings.GEOCAL_API_URL + queryString));
     }
     else if (!string.IsNullOrEmpty(location.City) && location.PostalCode.HasValue)
     {
         string queryString = $"?q={location.City.Trim()}&postcode={location.PostalCode}";
         return(GetCoordinatesFromUrl(AppSettings.GEOCAL_API_URL + queryString));
     }
     else
     {
         throw new BadRequestApiException($"Not enough fields completed in the {nameof(NullableLocationDto)} object.");
     }
 }
Example #2
0
 public IActionResult GetCoordinates([FromBody] NullableLocationDto location)
 {
     var(longitude, latitude) = service.GetCoordinates(location);
     return(Ok(new { longitude, latitude }));
 }