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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's an idea: Wrap the commas in <span>s with some… May 17, 2026 at 6:14 am
  • Editorial Team
    Editorial Team added an answer This topic is extensively covered in MSDN here. See the… May 17, 2026 at 6:14 am
  • Editorial Team
    Editorial Team added an answer The solution actually may be fairly simple, though it will… May 17, 2026 at 6:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I tried the following code in LINQPad and got the results given below: List<string>
Where is the proper place to perform validation given the following scenario/code below: In
Given the code below, wich is a very trimmed down version of the actual
Given the below code, will the method parameter y in Bar(int y) be assigned
Given the code bellow, how do I style the radio buttons to be next
The code below gives me this mysterious error, and i cannot fathom it. I
The code below gives an error: Property 'Int32 Key' is not defined for type
I've worked on many projects where I've been given code by others to update.
Given the code from the Complex Form part III how would you go about
Given the code: new Thread(new BackgroundWorker()).start(); Intuitively it feels like the BackgroundWorker instance should

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.