It's still not working, I have added in an extension from MireKE
import UIKit
import MapKit
import FirebaseDatabase
import FirebaseAuth
import CoreLocation
class venueDetails: UIViewController, CLLocationManagerDelegate {
var polyLineRenderer = MKPolylineRenderer()
var ref:FIRDatabaseReference!
var refHandle: UInt!
var databaseHandle: FIRDatabaseHandle!
var venue :Venue!
var latitude = Double()
var longitude = Double()
var londonLat = Double()
var londonLon = Double()
/
/
let manager = CLLocationManager()
@IBOutlet var mapView: MKMapView!
@IBOutlet var pubName: UILabel!
@IBOutlet var postCode: UILabel!
@IBOutlet var telephone: UILabel!
@IBOutlet var venueImage: UIImageView!
@IBOutlet var venueImage1: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.requestWhenInUseAuthorization()
manager.startUpdatingLocation()
let londonLat = self.manager.location?.coordinate.latitude
let londonLon = self.manager.location?.coordinate.longitude
/
/
let distancespan:CLLocationDegrees = 5000
let worthingLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(londonLat!, londonLon!)
mapView.setRegion(MKCoordinateRegionMakeWithDistance(worthingLocation, distancespan, distancespan), animated: true)
mapView.clipsToBounds = true
let worthingClassPin = mapAnnotation(title: "My Location", subtitle: "Here I am!", coordinate: worthingLocation, pinTintColor: UIColor.brown)
/
mapView.addAnnotation(worthingClassPin)
self.pubName.text = venue.rsPubName
self.postCode.text = venue.rsPostCode
self.telephone.text = venue.rsTel
let theImageURL = venue.rsImageURL
let theImageURL1 = venue.rsImageURL
let latName = venue.rsLat as? String
let lonName = venue.rsLong as? String
let latitude = Double(latName!) ?? 0.0
let longitude = Double(lonName!) ?? 0.0
let theTitle = venue.rsPubName
let subTitle = venue.rsTel
let thepostCode = venue.rsPostCode
let distancespan1:CLLocationDegrees = 5000
let theLocations:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
self.mapView.setRegion(MKCoordinateRegionMakeWithDistance(theLocations, distancespan1, distancespan), animated: true)
/
let worthingClassPin1 = mapAnnotation(title: theTitle!, subtitle: subTitle!, coordinate: theLocations, pinTintColor: UIColor.purple)
self.mapView.addAnnotation(worthingClassPin1)
venueImage.downloadedFrom(link: theImageURL!)
venueImage1.downloadedFrom(link: theImageURL1!)
/
/
}
@IBAction func showRoute(_ sender: Any) {
let sourceLocation = CLLocationCoordinate2D(latitude: Double(venue.rsLat) ?? 0.0, longitude: Double(venue.rsLong) ?? 0.0)
let destinationLocation = CLLocationCoordinate2D(latitude: (self.manager.location?.coordinate.latitude)!, longitude: (self.manager.location?.coordinate.longitude)!)
print("Source: \(sourceLocation)")
print("Source: \(destinationLocation)")
let sourcePlacemark = MKPlacemark(coordinate: sourceLocation, addressDictionary: nil)
let destinationPlacemark = MKPlacemark(coordinate: destinationLocation, addressDictionary: nil)
let sourceMapItem = MKMapItem(placemark: sourcePlacemark)
let destinationMapItem = MKMapItem(placemark: destinationPlacemark)
let directionRequest = MKDirectionsRequest()
directionRequest.source = sourceMapItem
directionRequest.destination = destinationMapItem
directionRequest.transportType = .automobile
let directions = MKDirections(request: directionRequest)
directions.calculate {
(response, error) -> Void in
guard let response = response else {
if let error = error {
print("Error: \(error)")
}
return
}
let route = response.routes[0]
self.mapView.add((route.polyline), level: MKOverlayLevel.aboveRoads)
let rect = route.polyline.boundingMapRect
self.mapView.setRegion(MKCoordinateRegionForMapRect(rect), animated: true)
/
}
}
}
extension UIImageView {
func downloadedFrom(url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit) {
contentMode = mode
URLSession.shared.dataTask(with: url) { (data, response, error) in
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let mimeType = response?.mimeType, mimeType.hasPrefix("image"),
let data = data, error == nil,
let image = UIImage(data: data)
else { return }
DispatchQueue.main.async() { () -> Void in
self.image = image
}
}.resume()
}
func downloadedFrom(link: String, contentMode mode: UIViewContentMode = .scaleAspectFit) {
guard let url = URL(string: link) else { return }
downloadedFrom(url: url, contentMode: mode)
}
}
extension venueDetails: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if polyLineRenderer == nil {
polyLineRenderer = MKPolylineRenderer(overlay: overlay)
polyLineRenderer.strokeColor = UIColor.blue
polyLineRenderer.lineWidth = 2.0
}
return polyLineRenderer
}
}
Please help