SHARE
TWEET

Untitled

a guest Nov 19th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  detailViewController.swift
  3. //  Hospital
  4. //
  5. //  Created by Wojciech Miśta on 17/10/2019.
  6. //  Copyright © 2019 Wojciech Miśta. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import CoreLocation
  11. import MapKit
  12.  
  13. var long:Double = 0.0
  14. var lat:Double = 0.0
  15. var address:Double = 0.0
  16. var name:String = ""
  17.  
  18. class detailViewController: UIViewController {
  19.  
  20.     @IBOutlet weak var hospitalTitle: UILabel!
  21.     @IBOutlet weak var hospitalAddress: UILabel!
  22.     @IBOutlet weak var mapButton: UIButton!
  23.    
  24.    
  25.     override func viewDidLoad() {
  26.         super.viewDidLoad()
  27.         print("IN NEW VIEW =>", myIndex)
  28.  
  29.  
  30.     }
  31.    
  32.     override func viewWillAppear(_ animated: Bool) {
  33.         long = hospitals[myIndex].long
  34.         lat = hospitals[myIndex].lat
  35.         name = hospitals[myIndex].name
  36.         hospitalTitle.text = hospitals[myIndex].name
  37.         hospitalAddress.text = hospitals[myIndex].address
  38.        
  39.     }
  40.  
  41.     func openMapForPlace() {
  42.  
  43.         let latitude:CLLocationDegrees =  lat
  44.         let longitude:CLLocationDegrees =  long
  45.  
  46.         let regionDistance:CLLocationDistance = 10000
  47.         let coordinates = CLLocationCoordinate2DMake(latitude, longitude)
  48.         let regionSpan = MKCoordinateRegion(center: coordinates, latitudinalMeters: regionDistance, longitudinalMeters: regionDistance)
  49.         let options = [
  50.             MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center),
  51.             MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span)
  52.         ]
  53.         let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil)
  54.         let mapItem = MKMapItem(placemark: placemark)
  55.         mapItem.name = "\(name)"
  56.         mapItem.openInMaps(launchOptions: options)
  57.  
  58.     }
  59.     @IBAction func mapButtonWasPressed(_ sender: Any) {
  60.         openMapForPlace()
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top