AutoCat/AutoCat/Controllers/Location/ShowEventController.swift

29 lines
1.2 KiB
Swift

import UIKit
import MapKit
import AutoCatCore
class ShowEventController: UIViewController {
private var map = MKMapView()
var event: VehicleEvent?
override func viewDidLoad() {
super.viewDidLoad()
self.map.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.map)
self.map.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
self.map.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
self.map.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
self.map.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
if let event = self.event {
self.title = event.address ?? String(format: "%.02f, %.02f", event.latitude, event.longitude)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: event.latitude, longitude: event.longitude), latitudinalMeters: 1000, longitudinalMeters: 1000)
self.map.setRegion(region, animated: true)
let pin = EventPin(event: event)
self.map.addAnnotation(pin)
}
}
}