Hi all,
Can anyone help me figure this one out?
foreach (var row in ttCustomer.ToList())
{
decimal? longi = row.Longitude_c;
decimal? lati = row.Latitude_c;
if (longi == null && lati == null)
{
Console.WriteLine("Both fields are null");
Ice.Diagnostics.Log.WriteEntry($"Updating the fields now..(Lat and Long)");
//Use open streetmaps to get our lat/long
var client = new RestClient("https://nominatim.openstreetmap.org/");
// Set the address parameter for the request
var request = new RestRequest("search?format=json&limit=1&q={address}", Method.GET);
//Lets build the address
string[] location = { row.Address1, row.Address2, row.Address3, row.City, row.State, row.Country, row.Zip };
string addr = string.Join(", ", location);
Ice.Diagnostics.Log.WriteEntry($"Address: {addr}");
//Append the address to the url of the request..
request.AddUrlSegment("address", addr);
// Execute the request and get the response
IRestResponse response = client.Execute(request);
Ice.Diagnostics.Log.WriteEntry($"Status code: {response.StatusCode}");
Ice.Diagnostics.Log.WriteEntry($"Error message: {response.ErrorMessage}");
// Deserialize the response into a list of search results
var searchResults = JsonConvert.DeserializeObject<List<SearchResult>>(response.Content);
Ice.Diagnostics.Log.WriteEntry($"Number of search results: {searchResults.Count}");
// Get the first search result
var firstResult = searchResults.FirstOrDefault();
if (firstResult == null)
{
this.PublishInfoMessage("First result is null",Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
}
else
{
// Update the latitude and longitude fields with the values from the search result
lati = firstResult.lat;
longi = firstResult.lon;
}
}
}
Need another pair of eyes, I can’t see my problem