Member-only story

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

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet