4

如何使用经度和纬度找到最近的机场?

任何特定的网络服务和任何数据库来实现?

4

5 回答 5

8

我发现的一个 WebService 是 airports.pidgets.com

这是一个例子:

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

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

[编辑] 在 Aviationweather.gov 上找到另一个网络服务(仅 XML 和 CSV)

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

您可以从这两个站点下载“静态”机场列表,以执行离线搜索。

问候

于 2014-02-26T17:32:01.547 回答
0

你在哪个平台上编码,Durga?是安卓吗?

在这种情况下,您可以使用 Google Maps API:

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

尤其是 Google 地方信息:

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

浏览他们的文档以获取详细信息。特别是,检查他们的许可证。

于 2012-09-30T11:19:10.297 回答
0
  1. 您需要一个包含机场纬度和经度字段的数据集
  2. 使用下面链接的页面上概述的大圆距离 (GCD) 的计算

维基百科关于 GCD 的文章

如果您需要进一步和更具体的帮助,请提供示例代码/指定语言

代码:

取自另一个网页(现已失效,使用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″&gt;</param>  
        /// <param name=”pos2″&gt;</param>  
        /// <param name=”type”&gt;</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;  
        }  
    }  
}  

伪代码:

这个伪代码应该会给你你正在寻找的答案。我没有对此进行测试,C# 可能会有语法错误,但它的要点应该很清楚。

/* 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
    }
}
于 2012-09-28T13:30:04.233 回答
0
this.nearestAirport = this.airports.find((airport) => {
              return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) &&
                      Math.round(airport.longitude) === Math.round(currentLocation.longitude));
            });
于 2016-12-26T12:05:15.593 回答
-1

查找最近的机场并获取从指定点 (Lat,Lan) 到达那里的路线

这是一个谷歌方法,没有任何数据库来实现这一点:

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

有关完整代码,请访问此处FULL NEAREST AIRPORT SCRIPT AND STYLE

查找最近的机场

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();
});
于 2012-11-07T12:10:59.733 回答