title: c# find the closest two numbers in a list with two columns to two number arguments
body: <p>I am working with Geographical Lat/Lon values and given a specific Lat/Lon combination, I need to find the closest Lat/Lon from a list of Lat/Lon locations based on US Zip Codes. Once located, I need to return the Zip Code for that location. </p>
  
  <p>Sample Arguments to Find the Closest Lat/Lon </p>
  
  <p>X: -76.696136 
  Y: 40.095702</p>
  
  <p>The DataTable Column includes Latitude, Longitude, ZipCode</p>
  
  <p>I've tried the below, but the distance between the two numbers returned is greater than expected, e.g. the ZipCode returned is a considerable distance from the original Lat/Lon argument. I am not confident the OrderBy, ThenBy is actually providing the closest combination of numbers. Is there another approach available that would provide a closer match?</p>
  
  <pre><code>var zipMatches = zipCodeList
   .OrderBy(item =&gt; Math.Abs(Convert.ToDouble(item.Latitude) - Convert.ToDouble(searchedItem.GeoLat)))
   .ThenBy(item =&gt; Math.Abs(Convert.ToDouble(item.Longitude) - Convert.ToDouble(searchedItem.GeoLon)))
   .FirstOrDefault();
  </code></pre>
  
  <p>The expected result would be a Lat/Lon pair closest to the arguments provided.</p>
  
  <p>X: -76.696136 
  Y: 40.095702</p>