Reputation: 127
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?
Upvotes: 0
Views: 3523
Reputation: 5128
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:
Use an alternate, open source of data such as OpenStreetMap.
Use a rendering library that draws such data for its basemap, such as Mapbox.
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.
Upvotes: 5