Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 737687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:45:00+00:00 2026-05-14T07:45:00+00:00

Given the code below, how do I compare a List of objects’s values with

  • 0

Given the code below, how do I compare a List of objects’s values with a test value?

I’m building a geolocation application. I’ll be passing in longitude and latitude and would like to have the service answer back with the location closest to those values.

I started down the path of converting to a string, and formatting the values down to two decimal places, but that seemed a bit too ghetto, and I’m looking for a more elegant solution.

public class Location : IEnumerable
{
    public string label { get; set; }
    public double lat { get; set; }
    public double lon { get; set; }

    //Implement IEnumerable
    public IEnumerator GetEnumerator()
    {
        return (IEnumerator)this;
    }

}
[HandleError]
public class HomeController : Controller
{
    private List<Location> myList = new List<Location>
 {             
    new Location {
        label="Atlanta Midtown", 
        lon=33.657674, 
        lat=-84.423130},
    new Location {
        label="Atlanta Airport", 
        lon=33.794151, 
        lat=-84.387228},
    new Location {
        label="Stamford, CT", 
        lon=41.053758, 
        lat=-73.530979}, ...
}

 public static int Main(String[] args)
 {
     string inLat = "-80.987654";
     double dblInLat = double.Parse(inLat);

     // here's where I would like to find the closest location to the inLat
     // once I figure out this, I'll implement the Longitude, and I'll be set
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:45:00+00:00Added an answer on May 14, 2026 at 7:45 am

    I found this which someone created that calculates distances between two distances across the globe using one of several different methods. I had to convert the .NET project to the updated VS2008, but that seemed to work fine. Then I just added this project to my solution and made a reference to it.

    My code then became:

    string inLat = "-80.987654";
    string inLon = "33.521478";
    var miles = GetNearestLocation(inLat, inLon);
    
    public double GetNearestLocation(string lat, string lon)
    {
        double dblInLat = double.Parse(lat);
        double dblInLon = double.Parse(lon);
    
        // instantiate the calculator
        GeodeticCalculator geoCalc = new GeodeticCalculator();
    
        // select a reference elllipsoid
        Ellipsoid reference = Ellipsoid.WGS84;
    
        // set user's current coordinates
        GlobalCoordinates userLocation;
        userLocation = new GlobalCoordinates(
            new Angle(dblInLon), new Angle(dblInLat)
        );
    
        // set example coordinates- when fully fleshed out, 
        //    this would be passed into this method
        GlobalCoordinates testLocation;
        testLocation= new GlobalCoordinates(
            new Angle(41.88253), new Angle(-87.624207) // lon, then lat
        );
    
        // calculate the geodetic curve
        GeodeticCurve geoCurve = geoCalc.CalculateGeodeticCurve(reference, userLocation, testLocation);
        double ellipseKilometers = geoCurve.EllipsoidalDistance / 1000.0;
        double ellipseMiles = ellipseKilometers * 0.621371192;
        /*
        Console.WriteLine("2-D path from input location to test location using WGS84");
        Console.WriteLine("   Ellipsoidal Distance: {0:0.00} kilometers ({1:0.00} miles)", ellipseKilometers, ellipseMiles);
        Console.WriteLine("   Azimuth:              {0:0.00} degrees", geoCurve.Azimuth.Degrees);
        Console.WriteLine("   Reverse Azimuth:      {0:0.00} degrees", geoCurve.ReverseAzimuth.Degrees);
        */
        return ellipseMiles;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for the Given below code after int Input Value of 46348 i am getting
Given the code below the method foo should compare operator-wise a given parameter bar
Given the code below, how would you create/implement SR.h so that it produces the
Given the code below ... Net::HTTP.start('localhost', 4000) do |http| # # usual stuff omitted
I was given the code below to disable a button on an ASP.Net page
Any ideas given the code below why the highlight is being triggered to run
Given the following code below, how can I have it modified such that it
Given the Java code below, what's the closest you could represent these two static
In the code given below, I need to position the userid box in the
In the code given below, I am trying to modify it in such a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.