-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMapView.swift
96 lines (82 loc) · 3.1 KB
/
MapView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// MapViewController.swift
// Sfest-swift
//
// Created by Peter Zignego on 7/4/14.
// Copyright (c) 2014 Launch Software. All rights reserved.
import UIKit
import MapKit
import CoreLocation
import Contacts
class MapView: MKMapView, CLLocationManagerDelegate {
var stageName: String?
let locationManager = CLLocationManager()
convenience init(stage:String) {
self.init()
frame = CGRect(x: 0, y: 45, width: UIScreen.mainScreen().bounds.size.width, height: UIScreen.mainScreen().bounds.size.height-45)
stageName = stage
setup()
userLocationManager()
}
func setup() {
let span = MKCoordinateSpan(latitudeDelta: 0.0025, longitudeDelta: 0.0025)
var location = userLocation.coordinate
switch stageName! {
case "BMO Harris Pavilion":
location.latitude = 43.02871
location.longitude = -87.89672
case "Briggs & Stratton Big Backyard":
location.latitude = 43.030026
location.longitude = -87.899661
case "Harley-Davidson Roadhouse":
location.latitude = 43.03103
location.longitude = -87.899731
case "Johnson Controls World Sound Stage":
location.latitude = 43.03344
location.longitude = -87.898385
case "Marcus Amphitheater":
location.latitude = 43.027339
location.longitude = -87.897701
case "Miller Lite Oasis":
location.latitude = 43.03209
location.longitude = -87.899892
case "U.S. Cellular Connection Stage":
location.latitude = 43.034468
location.longitude = -87.898444
case "Uline Warehouse":
location.latitude = 43.035354
location.longitude = -87.898178
default:
location.latitude = userLocation.coordinate.latitude
location.longitude = userLocation.coordinate.longitude
}
let region = MKCoordinateRegion(center: location, span: span)
setRegion(region, animated: true)
regionThatFits(region)
let mapPoint = MapPoint(coordinate: location, title: stageName!)
addAnnotation(mapPoint)
selectAnnotation(mapPoint, animated: true)
}
func userLocationManager() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
self.showsUserLocation = true
}
}
class MapPoint: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
init(coordinate: CLLocationCoordinate2D, title: String) {
self.coordinate = coordinate
self.title = title
}
func mapItem() -> MKMapItem {
let addressDictionary = [CNContactPostalAddressesKey as String : ""]
let placemark = MKPlacemark(coordinate: coordinate, addressDictionary: addressDictionary)
let mapItem = MKMapItem(placemark: placemark)
mapItem.name = title
return mapItem
}
}