如何使用经纬度来查找最近的机场?
是否有特定的网络服务或数据库可供使用?
如何使用经纬度来查找最近的机场?
是否有特定的网络服务或数据库可供使用?
我发现的一个Web服务是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上找到另一个Web服务(仅限XML和CSV)
你可以从这两个网站下载“静态”机场列表,以进行离线搜索。
祝好
如果您需要更具体的帮助,请提供示例代码/指定语言
代码:
从另一个网页中获取(现已失效,使用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;
}
}
}
伪代码:
这个伪代码应该能给你想要的答案。我没有测试过,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
}
}
https://developers.google.com/maps/
而且,特别是Google Places:
https://developers.google.com/places/
请浏览他们的文档以获取详细信息。特别是,请检查他们的许可证。
this.nearestAirport = this.airports.find((airport) => {
return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) &&
Math.round(airport.longitude) === Math.round(currentLocation.longitude));
});
查找最近的机场并获取从指定点(Lat,Lan)到达那里的方向
这里有一种谷歌方法,不需要任何数据库就可以实现:
onclick="getNeighbourhood('<%= propLat %>','<%= propLan %>');"
完整代码请访问此处 完整最近机场脚本和样式
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();
});