如何使用经度和纬度找到最近的机场?
任何特定的网络服务和任何数据库来实现?
我发现的一个 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)
您可以从这两个站点下载“静态”机场列表,以执行离线搜索。
问候
你在哪个平台上编码,Durga?是安卓吗?
在这种情况下,您可以使用 Google Maps API:
https://developers.google.com/maps/
尤其是 Google 地方信息:
https://developers.google.com/places/
浏览他们的文档以获取详细信息。特别是,检查他们的许可证。
如果您需要进一步和更具体的帮助,请提供示例代码/指定语言
代码:
取自另一个网页(现已失效,使用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
}
}
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 %>');"
有关完整代码,请访问此处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();
});