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 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure about what you're looking for exactly. Would… May 16, 2026 at 8:39 am
  • Editorial Team
    Editorial Team added an answer Unlike Algol-style languages like C#, Objective-C's syntax is specifically designed… May 16, 2026 at 8:39 am
  • Editorial Team
    Editorial Team added an answer According to the xlrd module documentation, the correct parameter is:… May 16, 2026 at 8:39 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 understand that the code given below will not be compltely understood unless i
Given my code below, is there a way that the first WebTestingApp constructor can
Given the code below, what does the with keyword do? I'm not very familiar
Given the code below, why is the foo(T*) function selected ? If I remove
Given the code below: void LookupBox_Load(object sender, EventArgs e) { Action d = delegate
Given the code below: class Sample { public static void Run() { int i
I want to create a list out of an xml file where only values
I have a LINQ query that populates a list of designers. Since I am
Here's the scenario... I have a table of subnets. (see below) I have an
This question comes from a need to ensure that changes I've made to code

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.