-1

My question is how can I find the minimum and maximum latitude and longitude of a specific area (150 miles) from the current location in one line of code in c#.

my case:- my lat/long is a/b and other lat/long is x/y and my search radius is 150 miles. I want to check x/y is in my search radius or not

I also have to try googling and I got link such like

Find Minimum/Maximum latitude and Longitude

But I don't know how it implements in my case.

KD_
  • 32
  • 9

1 Answers1

1

it is fairly straightforward to write a loop to get both minimum and maximum in each direction

    public static (LatLong min, LatLong max) MinMax(IEnumerable<LatLong> points)
    {
        using (var iter = points.GetEnumerator())
        {

            if (!iter.MoveNext())
            {
                throw new InvalidOperationException("No coordinates");
            }

            var min = iter.Current;
            var max = iter.Current;
            while (iter.MoveNext())
            {
                min = min.Min(iter.Current);
                max = max.Max(iter.Current);
            }

            return (min, max);
        }
    }

where Min/Max returns the minimum/maximum value for each component of the two coordinates.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • I can't test it right now but thank for help i'll update answer when i test this thanks @JonasH – KD_ Feb 05 '21 at 13:29