适用于多个目的地和单一来源的iOS MKDirections [英] iOS MKDirections for multiple destinations and a single source

查看:155
本文介绍了适用于多个目的地和单一来源的iOS MKDirections的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要从一组10中获得最接近的用户步行点。我已经看到MKDirections使用calculateDirectionsWithCompletionHandler为单个源目标位置执行此操作。我的问题是,我是否已经做了10个请求,然后检查哪个是距离最近的一个,或者有一种方法可以发送多个目的地并且响应是最接近的一个?

My application needs to get the "closest" walking point to the user from a set of 10. I have seen that MKDirections does this with "calculateDirectionsWithCompletionHandler" for a single source, destination locations. My question is, do I have do make 10 requests and then check which one is the closest one in distance or there is a way of sending multiple destinations and the response would be the closest one walking?

谢谢

推荐答案

据我所知,没有办法指定两点以上对于 MKDirections 请求。您提出的创建10个单独请求的解决方案应该在理论上有效,但请记住:

As far as I'm aware there is no way to specify more than two points for an MKDirections request. Your proposed solution of creating 10 separate requests should work in theory, though keep in mind that:


  1. MKDirections 不会在设备上本地计算路线,而是伸出远程API来计算它们并返回响应。如果您正在计算10条路线,则在等待返回所有结果时,用户可能会有明显的延迟。

  1. MKDirections does not calculate directions locally on the device, but reaches out to a remote API which calculates them and returns the response. If you're calculating 10 routes, there will likely be a noticeable delay for the user while waiting for all the results to be returned.

因为计算方向使用远程API,苹果公司可能会对此类事情感到不满 - 如果你过于频繁地使用他们的指示API,他们可能会限制你,或者如果他们发现这种情况发生,他们可能会拒绝提交到App Store的应用程序。

Because directions are calculated using a remote API, Apple likely would frown on something like this- if you're hitting their directions API too frequently they might throttle you, or they may just reject the app when it's submitted to the App Store if they see that this is happening.

我不确定您的确切要求,但根据您所需的准确性,一个解决方案可能是使用哈斯金公式计算起点和每个终点之间的距离,它会给你两点之间的距离如同苍蝇一样。因为您正在计算步行路线(与驾驶相反,而您只限于遵循特定道路并受交通限制),距离这些计算的最近距离可能是实际步行距离/时间最接近的距离,然后,您可以针对这些详细信息进行单个 MKDirections 请求。

I'm not sure of your exact requirements, but depending on the accuracy you need, one solution could be to calculate the distance between the start point and each end point using the haversine formula, which would give you the distance between the two points as-the-crow-flies. Because you're calculating walking directions (as opposed to driving, where you're limited to following specific roads and subject to traffic), the closest distance from these calculations will likely be the closest in terms of actual walking distance/time, at which point you could then make a single MKDirections request for those details.

这篇关于适用于多个目的地和单一来源的iOS MKDirections的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆