public static List <FirstResponder> GetRespondersInRadius(double radius, double Lat, double Lng) { var responders = new List <FirstResponder>(); using (var db = new RescContext()) { var positions = db.ActivePositions.Include(p => p.FirstResponder).ToList(); foreach (var position in positions) { var distance = GeoCoordinates.DistanceTo(Lat, Lng, position.Lat, position.Lng); if (distance < radius) { responders.Add(position.FirstResponder); } } } return(responders); }
public static double GetNearestStation(double Lat, double Lng) { Station nearestStation = null; double nearest = 150; using (var db = new RescContext()) { var stations = db.Stations.ToList(); foreach (var station in stations) { var distance = GeoCoordinates.DistanceTo(Lat, Lng, station.Lat, station.Lng); if (distance < nearest) { nearestStation = station; nearest = distance; } } } return(nearest); }