如何在Swift中在两个点(注解)之间绘制路线? [英] How to draw a route between two points(annotations) in Swift?

查看:110
本文介绍了如何在Swift中在两个点(注解)之间绘制路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to ask if somebody can help me with a bit of code...I don't know how to create a route in my map in Swift.I just can draw a polyline between two annotations but it goes out of the roads.How can I connect two annotations on map?but connect them on road...all these is for a bus tour.can somebody help me showing me the code for this in Swift?

推荐答案

为了跟踪这样的道路,您将需要道路几何形状的数据,但是Apple的API均未提供此信息.您将需要找到自己的地理数据源,其1)提供这些路线的点对点信息,以及2)匹配Apple Maps中绘制的路径,以便正确地跟踪线路.

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. 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.

这不是一个小问题.仅使用Apple技术不可能很好地做到这一点.

This is not a trivial problem. It's not likely to be done well using just Apple technology.

您可以完成此操作的一种方法是:

One way you could accomplish this is:

  1. 使用备用的开放数据源,例如 OpenStreetMap .

使用渲染库为其底图绘制此类数据,例如 Mapbox .

Use a rendering library that draws such data for its basemap, such as Mapbox.

将基于OSM数据的基础地图与基于单独路线的基于OSM的数据相结合,例如来自 Mapbox方向API .

Combine the OSM data-based base map with individual route OSM-based data such as from the Mapbox Directions API.

最重要的是,由于Apple的地图数据是封闭的,因此您不能保证在它上面绘制的任何内容都是完全匹配的.您需要渲染和路由数据来自同一源.

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. You need rendering and routing data to be from the same source.

这篇关于如何在Swift中在两个点(注解)之间绘制路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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