How to draw a route in mapKit?
Implement rendererFor
method.
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(polyline: overlay as! MKPolyline)
renderer.strokeColor = UIColor.red
renderer.lineWidth = 3
return renderer
}
Draw a path between two coordinates using MapKit Swift
Simply look at the documentation for MKDirectionsRequest
. There is a source
property and a destination
property.
The lines:
directionsRequest.setSource(MKMapItem(placemark: markSecondPoint))
directionsRequest.setDestination(MKMapItem(placemark: markFirstPoint))
become:
directionsRequest.source = MKMapItem(placemark: markSecondPoint)
directionsRequest.destination = MKMapItem(placemark: markFirstPoint)
Draw route on map in swift 4
Looks like Apple Maps doesn't yet support India. (quora.com/…) I guess if this is a critical part of your app, you may have to consider Google Maps
Those new coordinates are in India, and it just looks like directions are not available there. I get an error that says "Error Domain=MKErrorDomain Code=4 "Directions Not Available" UserInfo={NSLocalizedDescription=Directions Not Available, MKErrorGEOError=-8, MKErrorGEOErrorUserInfo={ }, MKErrorGEOTransitIncidentKey=<_GEOTransitRoutingIncidentMessage: 0x60800023df20>, MKDirectionsErrorCode=0, NSLocalizedFailureReason=Directions are not available between these locations.}"
Thanx Rob for this answar.
How to draw route between two locations and plot main points also using MapKit?
The question has been asked several times. I guess you are taking code from http://iosguy.com/2012/05/22/tracing-routes-with-mapkit/
You can also look at that SO question: Plotting Route with Multiple Points in iOS
You can get the code from http://iosboilerplate.com too and contribute to it.
And last but not least, there's a framework out there that can help you do it for a small sum of money (but nothing compared to what it would take you to do same):
http://www.cocoacontrols.com/controls/mtdirectionskit
Drawing a route in MapKit in iOS
This is a tricky one. There is no way to do that with MapKit: it's easy enough to draw lines when you know the coordinates, but MapKit won't give you access to the roads or other routing information. I'd say you need to call an external API to get your data.
I've been playing with cloudmade.com API. The vector stream server should return what you need, and then you can draw that over your map. However, discrepancies between the Google maps and the OSM maps used by cloudmade may make you want to use cloudmade maps all the way: they have an equivalent to MapKit.
P.S.: Other mapping providers - Google, Bing, etc. may also provide equivalent data feeds. I've just been looking at OSM/Cloudmade recently.
P.P.S.: None of this is trivial newbie stuff! Best of luck!
Related Topics
Add Uiview Banner Above Status Bar iOS 7
Xcode 4.3:Missing Icons for iOS Apps in Organizer's Archives
How to Implement Uitableview's Swipe to Delete for Uicollectionview
How to Get the Result Value of Alamofire.Request().Responsejson in Swift 2
Obj-C Afnetworking 2.0 Post Request Does Not Work
How to Increase Width of Textfield According to Typed Text
Setneedsdisplayinrect: Causes the Whole View to Be Updated
Uialertview in Swift, Getting Exc_Bad_Access
How to Get Selected Text from Uitextfield in Iphone
How to Get Previous and Next Month in Calendar-Swift
iOS 10 Heading Arrow for Mkuserlocation Dot
How to Write Keyboard Notifications in Swift 3
Uiview/Calayer: Transform Triggers Layoutsubviews in Superview
Strong Reference to a Weak References Inside Blocks
iOS 8 Nsinternalinconsistencyexception