Member-only story
Smooth MKPolyline to follow the road
2 min readNov 14, 2019
Get full code : https://github.com/javedmultani16/MapKitWithPolyLine
Here is code for the same:
var locRoute : MKRoute?
var directionsRequest = MKDirections.Request()
var arrayPlacemarks = [MKMapItem]() var selectedPin:MKPlacemark? = nil
let locationManager = CLLocationManager()
And write below code on ViewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()
locationSearchTable.mapView = mapView
mapView.delegate = self
}
Now go for delegate methods:
extension ViewController : MKMapViewDelegate {
func mapView(_: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location //Add source location as user location
let arrayPlacemarksource = MKPlacemark(coordinate: annotation.coordinate, addressDictionary: nil)
arrayPlacemarks.append(MKMapItem(placemark…