简体   繁体   English

使用iOS查找最近的机场

[英]Find nearest airport using iOS

I am writing an App that needs to find the closest international airports using the iPads GPS. 我正在编写一个应用程序,需要使用iPad GPS找到最近的国际机场。 Is there anyway of doing this easily? 无论如何这样做容易吗?

You may use the free services at GeoNames to search for nearby places. 您可以使用GeoNames的免费服务搜索附近的地方。 These can be filtered to only return airports as in this example: 这些可以过滤为仅返回机场,如下例所示:

http://ws.geonames.org/findNearbyJSON?lat=40&lng=9&radius=250&featureClass=S&featureCode=AIRP http://ws.geonames.org/findNearbyJSON?lat=40&lng=9&radius=250&featureClass=S&featureCode=AIRP

This will return all places designated as airports whether they are big or small. 这将返回指定为机场的所有地方,无论它们是大还是小。 You may need to tweak the parameters to better suit your needs. 您可能需要调整参数以更好地满足您的需求。

If you are looking for more filtered/proffesional searches, you may have a look at what companies like FlightStats offer. 如果您正在寻找更多过滤/专业搜索,您可以查看FlightStats等公司提供的服务。 These services are however not free. 然而,这些服务不是免费的。

Once you have a list of places (one way or the other) you can the get the distance to these using CoreLocation to calculate this with distanceFromLocation: 一旦你有一个地方列表(一种方式或另一种方式),你可以使用CoreLocation来获取这些地方的距离,用distanceFromLocation计算distanceFromLocation:

Do you already have the airport data? 你有机场数据吗?

If so, you'll start by creating a CLLocation for each airport. 如果是这样,您将首先为每个机场创建一个CLLocation。 Then you'll sort that list using a comparison method that returns [CLLocation distanceFromLocation:] . 然后,您将使用返回[CLLocation distanceFromLocation:]的比较方法对该列表进行排序。 That way you can sort your airport list by the closest to the current coordinates. 这样,您可以按最接近当前坐标的方式对机场列表进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM