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

霸气de小男生 提交于 2019-12-11 20:47:08

问题


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?


回答1:


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.

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. Use an alternate, open source of data such as OpenStreetMap.

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

  3. Combine the OSM data-based base map with individual route OSM-based data such as from the 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. You need rendering and routing data to be from the same source.



来源:https://stackoverflow.com/questions/26563854/how-to-draw-a-route-between-two-pointsannotations-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!