Geolocation 根据纬度和经度查找最近的机场
如何使用经度和纬度查找最近的机场 要实现任何特定的web服务和任何数据库Geolocation 根据纬度和经度查找最近的机场,geolocation,maps,Geolocation,Maps,如何使用经度和纬度查找最近的机场 要实现任何特定的web服务和任何数据库 您需要一个带有机场纬度和纬度字段的数据集 经度 使用大圆距离(GCD)的计算,如下面链接的页面所述 如果您需要更多具体帮助,请提供示例代码/指定语言 代码: 取自另一个网页(现已失效,已使用) 使用系统; 名称空间HaversineFormula { /// ///返回结果的距离类型。 /// 公共枚举距离类型{英里,公里}; /// ///指定纬度/经度点。 /// 公共结构位置 { 公
使用系统;
名称空间HaversineFormula
{
///
///返回结果的距离类型。
///
公共枚举距离类型{英里,公里};
///
///指定纬度/经度点。
///
公共结构位置
{
公共双纬度;
公共双经度;
}
哈弗森类
{
///
///返回任意两个的距离(以英里或公里为单位)
///纬度/经度点。
///
///
///
///
///
公共双距离(位置1、位置2、距离类型)
{
双R=(类型==距离类型.Miles)?3960:6371;
双dLat=这个.托拉第安(位置2.纬度-位置1.纬度);
double dLon=this.toRadian(pos2.Longitude-pos1.Longitude);
双a=Math.Sin(dLat/2)*Math.Sin(dLat/2)+
Math.Cos(this.toRadian(pos1.Latitude))*Math.Cos(this.toRadian(pos2.Latitude))*
数学单(dLon/2)*数学单(dLon/2);
double c=2*Math.Asin(Math.Min(1,Math.Sqrt(a));
双d=R*c;
返回d;
}
///
///转换成弧度。
///
///
///
私人双托拉迪安(双瓦尔)
{
返回值(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
}
}
/*设置参数*/
位置currentPosition=新位置();
位置airportPosition=新位置();
Double minDistance=Double.MaxValue;
字符串closestAirportName=“未知”;
哈弗森hv=新哈弗森();
/*设置当前位置,始终保持固定*/
当前位置纬度=0.000;
当前位置经度=0.000;
/*将到每个机场的距离与当前位置进行比较
*如果这是目前为止最近的机场,请保存结果*/
Foreach(机场中的机场){
airportPosition=新位置(airport.Lat、airport.Lon);
双距离到机场=高压距离(当前位置、机场位置、距离类型.公里)
if(到机场的距离杜尔加,你在哪个平台上编码?是安卓吗
在这种情况下,您可以使用Google Maps API:
特别是Google Places:
Broswe查看他们的文档以了解详细信息。尤其要检查他们的许可证。查找最近的机场,并获取从指定地点(Lat、Lan)到达机场的方向。
这里有一个Google方法,无需任何数据库即可实现此目的:
onclick="getNeighbourhood('<%= propLat %>','<%= propLan %>');"
我发现的一个Web服务是airports.pidgets.com
这是一个例子:
XML格式
JSon格式
[编辑]
在aviationweather.gov上找到另一个Web服务(仅XML和CSV)
您可以从这两个站点下载“静态”机场列表,以执行脱机搜索
关于对于堆栈溢出,这恐怕有点离题了。当您尝试集成到此类服务时,我们当然可以在代码方面为您提供帮助,但服务建议通常不客观。您可以发布到目前为止的示例代码吗?@user1273278:如果您需要沿地球曲面的距离算法的具体实现,我有一篇用SQL写的老博文:把它翻译成C#应该很简单,主要是括号、基本算术和内置的数学函数。可能是,我的问题写得不太清楚。当用户打开我的应用程序,我可以找到纬度和经度,使用这些参数我需要找到最近的机场。你有机场的LAT/Lon的数据,你想考虑吗?如果您这样做,则只需使用上面的Haversine函数依次计算从当前位置到每个机场的距离,并保存对任何机场的引用,该机场的距离比以前的任何机场都短。是的,我有机场数据库以及纬度和经度,我有用户当前位置(纬度和经度).我添加了伪代码来说明您需要的算法。您可以将自己的代码示例粘贴到问题中,以便提供特定的答案吗?在这种情况下,您可以在网页中使用Google Maps,并且可以从Javascript访问Google Maps/Places API。见:,和
this.nearestAirport = this.airports.find((airport) => {
return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) &&
Math.round(airport.longitude) === Math.round(currentLocation.longitude));
});
this.nearestAirport = this.airports.find((airport) => {
return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) &&
Math.round(airport.longitude) === Math.round(currentLocation.longitude));
});