Willcode4cash icon

Find coordinates within a given radius

Willcode4cash | PRO | 07/03/17 10:46:27 PM UTC | 0 ⭐ | 265 👁️ | Never ⏰ | []
C# |

610 B

|

None

|

0 👍

/

0 👎

    var lat = 40.646667; 
    var lng = -83.608611;
    var distance = 100;
 
    var towns = Towns.Select(t => new {
        TownId = t.TownID,
        Name = t.Name,
        State = t.State.Name,
        Distance =  (Math.Acos(
                        Math.Sin((lat * Math.PI / 180)) * 
                        Math.Sin(((double)t.Latitude * Math.PI / 180)) + 
                        Math.Cos((lat * Math.PI / 180)) * 
                        Math.Cos(((double)t.Latitude * Math.PI / 180)) *
                        Math.Cos(((lng - (Double)t.Longitude) * Math.PI / 180))
                    ) * 180 / Math.PI) * 60 * 1.1515 * 1.609344
    }).ToList();
    towns
        .Where(t => t.Distance <= distance)
        .OrderBy(t => t.Distance).Dump();

Comments