简体   繁体   English

如何在Swift中在两个点(注解)之间绘制路线?

[英]How to draw a route between two points(annotations) in Swift?

我想问问是否有人可以帮我一些代码...我不知道如何在Swift中的地图中创建路线,我只能在两个注解之间绘制一条折线,但它不可行我如何在地图上连接两个注释?但在道路上连接它们...所有这些都是为了游览公共汽车。有人可以帮我在Swift中向我展示此代码吗?

In order to trace a road like this, you will need data for the road geometry, but none of Apple's APIs provide this info. 为了跟踪这样的道路,您将需要道路几何形状的数据,但是Apple的API均未提供此信息。 You will need to find your own source of geo data that both 1) provides point-by-point info for these routes as well as 2) matches the paths drawn in Apple Maps so that you trace lines up properly. 您将需要找到自己的地理数据源,其1)提供这些路线的点对点信息,以及2)匹配Apple Maps中绘制的路径,以便正确地跟踪线路。

This is not a trivial problem. 这不是一个小问题。 It's not likely to be done well using just Apple technology. 仅使用Apple技术不可能很好地做到这一点。

One way you could accomplish this is: 您可以完成此操作的一种方法是:

  1. Use an alternate, open source of data such as OpenStreetMap . 使用替代的开放数据源,例如OpenStreetMap

  2. Use a rendering library that draws such data for its basemap, such as Mapbox . 使用为其底图绘制此类数据的渲染库,例如Mapbox

  3. Combine the OSM data-based base map with individual route OSM-based data such as from the Mapbox Directions API . 将基于OSM数据的基础地图与基于路线的基于OSM的数据(例如来自Mapbox Directions API)组合在一起

The bottom line is that since Apple's maps data is closed, you can't guarantee that anything you draw on top of it is an exact matchup. 最重要的是,由于Apple的地图数据是封闭的,因此您不能保证在它上面绘制的任何内容都是完全匹配的。 You need rendering and routing data to be from the same source. 您需要渲染和路由数据来自同一源。

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

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