Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li>You need a dataset with fields for the airport`s latitude and longitude</li> <li>Use the calculation for Great-Circle distance (GCD) as outlined on the page linked below</li> </ol> <p><a href="http://en.wikipedia.org/wiki/Great-circle_distance" rel="nofollow" title="on Wikipedia">Wikipedia article on GCD</a></p> <p>Please provide example code/specify the language if you would like further and more specific help</p> <p><strong>CODE:</strong></p> <p>Taken from another webpage (now defunct, used <a href="http://web.archive.org/web/20101228001530/http://www.codecodex.com/wiki/Calculate_Distance_Between_Two_Points_on_a_Globe#C.23" rel="nofollow">waybackmachine</a>)</p> <pre><code>using System; namespace HaversineFormula { /// &lt;summary&gt; /// The distance type to return the results in. /// &lt;/summary&gt; public enum DistanceType { Miles, Kilometers }; /// &lt;summary&gt; /// Specifies a Latitude / Longitude point. /// &lt;/summary&gt; public struct Position { public double Latitude; public double Longitude; } class Haversine { /// &lt;summary&gt; /// Returns the distance in miles or kilometers of any two /// latitude / longitude points. /// &lt;/summary&gt; /// &lt;param name=”pos1″&gt;&lt;/param&gt; /// &lt;param name=”pos2″&gt;&lt;/param&gt; /// &lt;param name=”type”&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public double Distance(Position pos1, Position pos2, DistanceType type) { double R = (type == DistanceType.Miles) ? 3960 : 6371; double dLat = this.toRadian(pos2.Latitude - pos1.Latitude); double dLon = this.toRadian(pos2.Longitude - pos1.Longitude); double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(this.toRadian(pos1.Latitude)) * Math.Cos(this.toRadian(pos2.Latitude)) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a))); double d = R * c; return d; } /// &lt;summary&gt; /// Convert to Radians. /// &lt;/summary&gt; /// &lt;param name="val"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; private double toRadian(double val) { return (Math.PI / 180) * val; } } } </code></pre> <p><strong>Pseudocode:</strong></p> <p>This pseudocode should give you the answer you are looking for. I didn't test this and the C# will probably have syntactic errors but the gist of it should be clear.</p> <pre><code>/* Set parameters */ Position currentPosition = new Position(); Position airportPosition = new Position(); Double minDistance = Double.MaxValue; String closestAirportName = "UNKNOWN"; Haversine hv = new Haversine(); /* Set current position, remains fixed throughout */ currentPosition.Latitude = 0.000; currentPosition.Longitude = 0.000; /* Compare distance to each airport with current location * and save results if this is the closest airport so far*/ Foreach (airport in airports) { airportPosition = new Position(airport.Lat, airport.Lon); Double distanceToAirport = hv.Distance(currentPosition, airportPosition, DistanceType.Kilometers) if (distanceToAirport &lt; minDistance) { minDistance = distanceToAirport closestAirportName = airport.Name } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload