Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.71 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  Public Art
  4. //
  5. //  Created by Tom Kearsley on 8/11/16.
  6. //  Copyright © 2016 Tom Kearsley. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import MapKit
  11. import CoreLocation
  12.  
  13. class ViewController: UIViewController, MKMapViewDelegate,CLLocationManagerDelegate {
  14.  
  15.     @IBOutlet weak var MapView: MKMapView!
  16.     let manager = CLLocationManager()
  17.     var artworkPin:Artwork!
  18.     var artworkPin2:Artwork!
  19.    
  20.     func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  21.         //let location = locations[0]
  22.        
  23.        
  24.         //let span:MKCoordinateSpan = MKCoordinateSpanMake(0.02, 0.02)
  25.        
  26.         //let myLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
  27.        
  28.        
  29.     }
  30.     override func viewDidLoad() {
  31.         super.viewDidLoad()
  32.        
  33.         // tracking user's location
  34.         manager.delegate = self
  35.         manager.desiredAccuracy = kCLLocationAccuracyBest
  36.         manager.requestWhenInUseAuthorization()
  37.         manager.startUpdatingLocation()
  38.        
  39.         // Setting up Map
  40.         let distanceSpan:CLLocationDegrees = 2000
  41.         MapView.setRegion(MKCoordinateRegionMakeWithDistance(CLLocationCoordinate2DMake(-39.0556253, 174.0752278), distanceSpan, distanceSpan), animated: true)
  42.         MapView.showsUserLocation = true
  43.         MapView.delegate = self
  44.        
  45.         // artwork on map
  46.         let windwandcoord: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.055961,174.072288)
  47.         let windwandcoord2: CLLocationCoordinate2D = CLLocationCoordinate2DMake(-39.055901,174.070208)
  48.         artworkPin = Artwork(title:"Wind Wand",locationName:"Majestic",discipline:"Statue",
  49.                                  coordinate:windwandcoord)
  50.         artworkPin2 = Artwork(title:"Collateral Damage",locationName:" Not Majestic",discipline:"Statue",
  51.                              coordinate:windwandcoord2)
  52.         MapView.addAnnotation(artworkPin)
  53.         MapView.addAnnotation(artworkPin2)
  54.        
  55.     }
  56.    
  57.    
  58.     func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
  59.     {
  60.         if annotation is MKUserLocation {return nil}
  61.        
  62.         let reuseId = "pin"
  63.        
  64.         var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView
  65.         if pinView == nil {
  66.             pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
  67.             pinView!.canShowCallout = true
  68.             pinView!.animatesDrop = true
  69.             pinView!.calloutOffset = CGPoint(x: -5, y: 5)
  70.             let calloutButton = UIButton(type: .detailDisclosure)
  71.             pinView!.rightCalloutAccessoryView = calloutButton
  72.             pinView!.sizeToFit()
  73.         }
  74.         else {
  75.             pinView!.annotation = annotation
  76.         }
  77.        
  78.        
  79.         return pinView
  80.     }
  81.    
  82.    
  83.    
  84.     func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
  85.         if control == view.rightCalloutAccessoryView {
  86.             if let artworkPin = view.annotation as? Artwork {
  87.                 performSegue(withIdentifier: "no", sender: artworkPin)
  88.             }
  89.         }
  90.     }
  91.    
  92.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  93.         if let identifier = segue.identifier {
  94.             if identifier == "no" {
  95.                 if let artworkPin = sender as? Artwork {
  96.                     let ViewTwo = segue.destination as! ViewTwo
  97.                     ViewTwo.artworkPin = artworkPin
  98.                 }
  99.             }
  100.         }
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement