Find the nearest airport based on latitude and longitude

How to find the nearest airport using longitude and latitude?

Any specific web services and any database to achieve?

+4
source share
5 answers
  • You need a dataset with fields for airport latitude and longitude
  • Use the calculation for the Grand Circle distance (GCD) as indicated on the page below.

Wikipedia article on GCD

Please provide an example code / indicate the language if you want additional and more specific help.

CODE:

Taken from another webpage (currently non-existent, using waybackmachine )

using System; namespace HaversineFormula { /// <summary> /// The distance type to return the results in. /// </summary> public enum DistanceType { Miles, Kilometers }; /// <summary> /// Specifies a Latitude / Longitude point. /// </summary> public struct Position { public double Latitude; public double Longitude; } class Haversine { /// <summary> /// Returns the distance in miles or kilometers of any two /// latitude / longitude points. /// </summary> /// <param name="pos1β€³></param> /// <param name="pos2β€³></param> /// <param name="type"></param> /// <returns></returns> 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; } /// <summary> /// Convert to Radians. /// </summary> /// <param name="val"></param> /// <returns></returns> private double toRadian(double val) { return (Math.PI / 180) * val; } } } 

pseudo code:

This pseudo code should give you the answer you are looking for. I have not tested this, and C # will probably have syntax errors, but the gist of this should be clear.

 /* 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 < minDistance) { minDistance = distanceToAirport closestAirportName = airport.Name } } 
0
source

One web service I found is airport.pidgets.com

This is an example:

XML format http://airports.pidgets.com/v1/airports?near=45.3515,9.3753

JSon format http://airports.pidgets.com/v1/airports?near=45.3515,9.3753&format=json

[Edit] Found another web service on the aviation platform (XML and CSV only)

http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=stations&requestType=retrieve&format=xml&radialDistance=20;9.3753,45.3515

From both sites, you can download a β€œstatic” list of airports to perform an offline search.

Hello

+7
source

What platform are you coding for, Durga? Is it Android?

In this case, you can use the Google Maps API:

https://developers.google.com/maps/

and in particular Google Places:

https://developers.google.com/places/

Tell us about your documentation. In particular, check their license.

0
source
 this.nearestAirport = this.airports.find((airport) => { return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) && Math.round(airport.longitude) === Math.round(currentLocation.longitude)); }); 
0
source

Find the nearest airport and get directions to get there from the indicated point (Lat, Lan)

The following is a Google method without any database :

 onclick="getNeighbourhood('<%= propLat %>','<%= propLan %>');" 

For the full code, here is the FULL NEAREST SCRIPT AIRPORT AND STYLE

Find nearest airport

 function getNeighbourhood(propLatQ,propLanQ) { propLat=propLatQ; propLan=propLanQ; var myLatlng = new google.maps.LatLng(propLat,propLan); var myOptions = { zoom: 8, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map"), myOptions); places = new google.maps.places.PlacesService(map); google.maps.event.addListener(map, 'tilesloaded', tilesLoaded); autocomplete = new google.maps.places.Autocomplete(document.getElementById('autocomplete')); google.maps.event.addListener(autocomplete, 'place_changed', function() { showSelectedPlace(); }); 
-1
source

Source: https://habr.com/ru/post/1436815/


All Articles