如何使用经度和纬度找到最近的机场?
任何特定的Web服务和任何数据库实现?
答案 0 :(得分:7)
我找到的一个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)
您可以从这两个站点下载“静态”机场列表,以执行离线搜索。
此致
答案 1 :(得分:0)
如果您想获得更多更具体的帮助,请提供示例代码/指定语言
<强> CODE:强>
取自其他网页(现已解散,使用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
}
}
答案 2 :(得分:0)
你在哪个平台编码,杜尔加?是Android吗?
在这种情况下,您可以使用Google Maps API:
https://developers.google.com/maps/
,特别是Google商家信息:
https://developers.google.com/places/
Broswe他们的文档了解详情。特别是,检查他们的许可证。
答案 3 :(得分:0)
this.nearestAirport = this.airports.find((airport) => {
return (Math.round(airport.latitude) === Math.round(currentLocation.latitude) &&
Math.round(airport.longitude) === Math.round(currentLocation.longitude));
});
答案 4 :(得分:-1)
查找最近的机场并获取从指定地点(Lat,Lan)到达那里的路线
以下是Google方法,没有任何数据库来实现此目的:
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();
});